Class: Trek::Generators::Install::AuthenticationGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Trek::Generators::Install::AuthenticationGenerator
- Includes:
- Rails::Generators::Migration, Helpers
- Defined in:
- lib/generators/trek/install/authentication_generator.rb
Constant Summary collapse
- USER_MODEL_CLASS_NAME =
"User".freeze
Instance Method Summary collapse
- #add_admin_auth_routes ⇒ Object
- #add_bcrypt_gem ⇒ Object
- #autocorrect_user_model ⇒ Object
- #copy_admin_authentication_concern ⇒ Object
- #copy_user_session_model ⇒ Object
- #copy_user_sessions_migration ⇒ Object
- #inject_authentication_into_user_model ⇒ Object
Instance Method Details
#add_admin_auth_routes ⇒ Object
47 48 49 50 51 52 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 47 def add_admin_auth_routes route "resource :user_session, only: %i[new create destroy]", namespace: :admin route "resources :user_password_resets, param: :token, only: %i[new create edit update]", namespace: :admin route 'get :login, to: "user_sessions#new", as: :login', namespace: :admin route 'delete :logout, to: "user_sessions#destroy", as: :logout', namespace: :admin end |
#add_bcrypt_gem ⇒ Object
18 19 20 21 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 18 def add_bcrypt_gem gem "bcrypt", "~> 3.1.7" unless in_gemfile?("bcrypt") run "bundle install --quiet", abort_on_failure: true end |
#autocorrect_user_model ⇒ Object
54 55 56 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 54 def autocorrect_user_model run "rubocop --autocorrect #{user_model_path}" end |
#copy_admin_authentication_concern ⇒ Object
23 24 25 26 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 23 def copy_admin_authentication_concern template "controllers/concerns/trek/authentication.rb", "app/controllers/concerns/trek/authentication.rb" end |
#copy_user_session_model ⇒ Object
28 29 30 31 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 28 def copy_user_session_model template "models/user_session.rb", "app/models/user_session.rb" end |
#copy_user_sessions_migration ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 33 def copy_user_sessions_migration return unless defined?(ActiveRecord) migration_template("migrations/user_sessions.rb.erb", "db/migrate/trek_user_sessions.rb", migration_class_name:) end |
#inject_authentication_into_user_model ⇒ Object
41 42 43 44 45 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 41 def inject_authentication_into_user_model inject_into_class user_model_path, USER_MODEL_CLASS_NAME, user_model_injection end |