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::MagicLink, Features::Ott, Features::Passkey, 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.
-
#format_user_model ⇒ Object
Runs after every feature install so the blank line separates the concern includes (if any) from the rest of the class body, no matter which features are enabled.
- #install_base_authentication ⇒ Object
- #install_confirmable ⇒ Object
- #install_invitable ⇒ Object
- #install_lockable ⇒ Object
- #install_magic_link ⇒ Object
- #install_ott ⇒ Object
- #install_passkey ⇒ 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.
142 143 144 145 146 |
# File 'lib/generators/authentication/authentication_generator.rb', line 142 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 |
#format_user_model ⇒ Object
Runs after every feature install so the blank line separates the concern includes (if any) from the rest of the class body, no matter which features are enabled.
134 135 136 |
# File 'lib/generators/authentication/authentication_generator.rb', line 134 def format_user_model inject_into_file "app/models/user.rb", "\n", after: /(?: include \w+Concern\n)+/, force: true end |
#install_base_authentication ⇒ Object
78 79 80 81 |
# File 'lib/generators/authentication/authentication_generator.rb', line 78 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
95 96 97 |
# File 'lib/generators/authentication/authentication_generator.rb', line 95 def install_confirmable generate_confirmable if confirmable? end |
#install_invitable ⇒ Object
115 116 117 |
# File 'lib/generators/authentication/authentication_generator.rb', line 115 def install_invitable generate_invitable if invitable? end |
#install_lockable ⇒ Object
111 112 113 |
# File 'lib/generators/authentication/authentication_generator.rb', line 111 def install_lockable generate_lockable if lockable? end |
#install_magic_link ⇒ Object
119 120 121 |
# File 'lib/generators/authentication/authentication_generator.rb', line 119 def install_magic_link generate_magic_link if magic_link? end |
#install_ott ⇒ Object
123 124 125 |
# File 'lib/generators/authentication/authentication_generator.rb', line 123 def install_ott generate_ott if ott? end |
#install_passkey ⇒ Object
127 128 129 |
# File 'lib/generators/authentication/authentication_generator.rb', line 127 def install_passkey generate_passkey if passkey? end |
#install_recoverable ⇒ Object
91 92 93 |
# File 'lib/generators/authentication/authentication_generator.rb', line 91 def install_recoverable generate_recoverable if recoverable? end |
#install_registerable ⇒ Object
87 88 89 |
# File 'lib/generators/authentication/authentication_generator.rb', line 87 def install_registerable generate_registerable if registerable? end |
#install_rememberable ⇒ Object
99 100 101 |
# File 'lib/generators/authentication/authentication_generator.rb', line 99 def install_rememberable generate_rememberable if rememberable? end |
#install_timeoutable ⇒ Object
107 108 109 |
# File 'lib/generators/authentication/authentication_generator.rb', line 107 def install_timeoutable generate_timeoutable if timeoutable? end |
#install_trackable ⇒ Object
103 104 105 |
# File 'lib/generators/authentication/authentication_generator.rb', line 103 def install_trackable generate_trackable if trackable? end |
#install_validatable ⇒ Object
83 84 85 |
# File 'lib/generators/authentication/authentication_generator.rb', line 83 def install_validatable generate_validatable if validatable? end |