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



14
15
16
17
18
19
# File 'lib/generators/spree/custom_user/custom_user_generator.rb', line 14

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



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/spree/custom_user/custom_user_generator.rb', line 21

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"

  initializer 'solidus_authentication', <<~RUBY
    Rails.application.config.to_prepare do
      ApplicationController.include Spree::AuthenticationHelpers, Spree::CurrentUserHelpers
      Spree::Api::BaseController.include Spree::CurrentUserHelpers if defined? Spree::Api
    end
  RUBY

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