Class: RailsAuthentication::Generators::AuthenticationGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RailsAuthentication::Generators::AuthenticationGenerator
- 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
-
#customize_session_layer ⇒ Object
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.
- #install_base_authentication ⇒ Object
- #install_confirmable ⇒ Object
- #install_invitable ⇒ Object
- #install_lockable ⇒ Object
- #install_recoverable ⇒ Object
- #install_registerable ⇒ Object
- #install_rememberable ⇒ Object
- #install_timeoutable ⇒ Object
- #install_trackable ⇒ Object
- #install_validatable ⇒ Object
Instance Method Details
#customize_session_layer ⇒ Object
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_authentication ⇒ Object
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_confirmable ⇒ Object
73 74 75 |
# File 'lib/generators/authentication/authentication_generator.rb', line 73 def install_confirmable generate_confirmable if confirmable? end |
#install_invitable ⇒ Object
93 94 95 |
# File 'lib/generators/authentication/authentication_generator.rb', line 93 def install_invitable generate_invitable if invitable? end |
#install_lockable ⇒ Object
89 90 91 |
# File 'lib/generators/authentication/authentication_generator.rb', line 89 def install_lockable generate_lockable if lockable? end |
#install_recoverable ⇒ Object
69 70 71 |
# File 'lib/generators/authentication/authentication_generator.rb', line 69 def install_recoverable generate_recoverable if recoverable? end |
#install_registerable ⇒ Object
65 66 67 |
# File 'lib/generators/authentication/authentication_generator.rb', line 65 def install_registerable generate_registerable if registerable? end |
#install_rememberable ⇒ Object
77 78 79 |
# File 'lib/generators/authentication/authentication_generator.rb', line 77 def install_rememberable generate_rememberable if rememberable? end |
#install_timeoutable ⇒ Object
85 86 87 |
# File 'lib/generators/authentication/authentication_generator.rb', line 85 def install_timeoutable generate_timeoutable if timeoutable? end |
#install_trackable ⇒ Object
81 82 83 |
# File 'lib/generators/authentication/authentication_generator.rb', line 81 def install_trackable generate_trackable if trackable? end |
#install_validatable ⇒ Object
61 62 63 |
# File 'lib/generators/authentication/authentication_generator.rb', line 61 def install_validatable generate_validatable if validatable? end |