Class: RailsAuthentication::Generators::AuthenticationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration, Features::Confirmable, Features::Invitable, Features::Lockable, Features::Recoverable, Features::Registerable, Features::Rememberable, Features::Timeoutable, Features::Trackable, Features::Validatable
Defined in:
lib/generators/authentication/authentication_generator.rb

Overview

Shadows Rails' built-in bin/rails generate authentication command: the explicit authentication:authentication namespace is checked before Rails' own rails:authentication, so the bare authentication invocation lands here. It runs the built-in generator first, then layers the feature set on top.

The Ruby namespace is RailsAuthentication (not Authentication, which would give the same Thor namespace implicitly) because Rails 8's base generator creates an Authentication controller concern in the host app — a top-level constant this gem must not squat on.

Constant Summary collapse

FEATURES =
%i[
  confirmable recoverable registerable rememberable trackable
  timeoutable validatable lockable invitable
].freeze

Instance Method Summary collapse

Instance Method Details

#customize_session_layerObject

Confirmable, Rememberable, Trackable, Timeoutable, and Lockable all hook into the sign-in flow, so the base generator's session files are replaced with versions rendered from the enabled feature set. Overwriting is safe: the base copies were written moments ago by this same run.



101
102
103
104
105
# File 'lib/generators/authentication/authentication_generator.rb', line 101

def customize_session_layer
  template "app/controllers/sessions_controller.rb", force: true
  template "app/controllers/concerns/authentication.rb", force: true
  template "app/views/sessions/new.html.erb", force: true
end

#install_base_authenticationObject



56
57
58
59
# File 'lib/generators/authentication/authentication_generator.rb', line 56

def install_base_authentication
  say "Running Rails' built-in authentication generator", :green
  Rails::Generators.invoke("rails:authentication", [], behavior: behavior, destination_root: destination_root)
end

#install_confirmableObject



73
74
75
# File 'lib/generators/authentication/authentication_generator.rb', line 73

def install_confirmable
  generate_confirmable if confirmable?
end

#install_invitableObject



93
94
95
# File 'lib/generators/authentication/authentication_generator.rb', line 93

def install_invitable
  generate_invitable if invitable?
end

#install_lockableObject



89
90
91
# File 'lib/generators/authentication/authentication_generator.rb', line 89

def install_lockable
  generate_lockable if lockable?
end

#install_recoverableObject



69
70
71
# File 'lib/generators/authentication/authentication_generator.rb', line 69

def install_recoverable
  generate_recoverable if recoverable?
end

#install_registerableObject



65
66
67
# File 'lib/generators/authentication/authentication_generator.rb', line 65

def install_registerable
  generate_registerable if registerable?
end

#install_rememberableObject



77
78
79
# File 'lib/generators/authentication/authentication_generator.rb', line 77

def install_rememberable
  generate_rememberable if rememberable?
end

#install_timeoutableObject



85
86
87
# File 'lib/generators/authentication/authentication_generator.rb', line 85

def install_timeoutable
  generate_timeoutable if timeoutable?
end

#install_trackableObject



81
82
83
# File 'lib/generators/authentication/authentication_generator.rb', line 81

def install_trackable
  generate_trackable if trackable?
end

#install_validatableObject



61
62
63
# File 'lib/generators/authentication/authentication_generator.rb', line 61

def install_validatable
  generate_validatable if validatable?
end