Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for custom user generator #2382

Merged
merged 6 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions core/lib/generators/spree/custom_user/custom_user_generator.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
require 'rails/generators/active_record/migration'

module Spree
class CustomUserGenerator < Rails::Generators::NamedBase
include Rails::Generators::ResourceHelpers
include Rails::Generators::Migration
include ActiveRecord::Generators::Migration

desc "Set up a Solidus installation with a custom User class"

def self.source_paths
paths = superclass.source_paths
paths << File.expand_path('../templates', __FILE__)
paths.flatten
end
source_root File.expand_path('templates', File.dirname(__FILE__))

def check_for_constant
klass
klass
rescue NameError
@shell.say "Couldn't find #{class_name}. Are you sure that this class exists within your application and is loaded?", :red
exit(1)
@shell.say "Couldn't find #{class_name}. Are you sure that this class exists within your application and is loaded?", :red
exit(1)
end

def generate
Expand All @@ -24,22 +21,14 @@ def generate

file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file
send(file_action, 'config/initializers/spree.rb') do
%{
Rails.application.config.to_prepare do
require_dependency 'spree/authentication_helpers'
end\n}
"Rails.application.config.to_prepare do\n require_dependency 'spree/authentication_helpers'\nend\n"
end
end

def self.next_migration_number(dirname)
if ActiveRecord::Base.timestamped_migrations
sleep 1 # make sure to get a different migration every time
Time.new.utc.strftime("%Y%m%d%H%M%S")
else
"%.3d" % (current_migration_number(dirname) + 1)
end
gsub_file 'config/initializers/spree.rb', /Spree\.user_class.?=.?.+$/, %{Spree.user_class = "#{class_name}"}
end

private

def klass
class_name.constantize
end
Expand Down

This file was deleted.