Class: Spree::CustomUserGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/spree/custom_user/custom_user_generator.rb

Instance Method Summary collapse

Instance Method Details

#check_for_constantObject



11
12
13
14
15
16
# File 'lib/generators/spree/custom_user/custom_user_generator.rb', line 11

def check_for_constant
  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)
end

#generateObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/spree/custom_user/custom_user_generator.rb', line 18

def generate
  migration_template 'migration.rb.tt', "db/migrate/add_spree_fields_to_custom_user_table.rb"
  template 'authentication_helpers.rb.tt', "lib/spree/authentication_helpers.rb"

  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\n  require_dependency 'spree/authentication_helpers'\nend\n"
  end

  gsub_file 'config/initializers/spree.rb', /Spree\.user_class.?=.?.+$/, %{Spree.user_class = "#{class_name}"}
end