Class: Spree::Authentication::DummyGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/spree/authentication/dummy/dummy_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_pathsObject



8
9
10
11
12
# File 'lib/generators/spree/authentication/dummy/dummy_generator.rb', line 8

def self.source_paths
  paths = superclass.source_paths
  paths << File.expand_path('templates', __dir__)
  paths.flatten
end

Instance Method Details

#configure_authentication_helpersObject



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

def configure_authentication_helpers
  file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file
  send(file_action, 'config/initializers/spree.rb') do
    <<~RUBY

      Rails.application.config.to_prepare do
        require_dependency 'spree/authentication_helpers'
      end
    RUBY
  end
end

#create_admin_users_migrationObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/spree/authentication/dummy/dummy_generator.rb', line 30

def create_admin_users_migration
  # Use a fixed early timestamp (20210913) to ensure this migration runs BEFORE
  # any Spree core migrations that reference spree_admin_users table.
  # The earliest such migration is 20250122113708_add_first_and_last_name_to_spree_admin_class.rb
  # We use a timestamp before the main Spree migration (20210914000000_spree_four_three.rb)
  migration_file = File.join('db', 'migrate', '20210913000000_create_spree_admin_users.rb')

  # Skip if migration already exists
  return if File.exist?(migration_file) || migration_exists?('create_spree_admin_users')

  template 'create_spree_admin_users.rb.tt', migration_file
end

#create_authentication_helpersObject



14
15
16
# File 'lib/generators/spree/authentication/dummy/dummy_generator.rb', line 14

def create_authentication_helpers
  template 'authentication_helpers.rb.tt', 'lib/spree/authentication_helpers.rb'
end