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
49 50 51 52 53 54 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 49 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 22 23 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 18 def add_bcrypt_gem return if in_gemfile?("bcrypt") gem "bcrypt", "~> 3.1.7" bundle_install end |
#autocorrect_user_model ⇒ Object
56 57 58 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 56 def autocorrect_user_model run "rubocop --autocorrect #{user_model_path}" end |
#copy_admin_authentication_concern ⇒ Object
25 26 27 28 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 25 def copy_admin_authentication_concern template "controllers/concerns/trek/authentication.rb", "app/controllers/concerns/trek/authentication.rb" end |
#copy_user_session_model ⇒ Object
30 31 32 33 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 30 def copy_user_session_model template "models/user_session.rb", "app/models/user_session.rb" end |
#copy_user_sessions_migration ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 35 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
43 44 45 46 47 |
# File 'lib/generators/trek/install/authentication_generator.rb', line 43 def inject_authentication_into_user_model inject_into_class user_model_path, USER_MODEL_CLASS_NAME, user_model_injection end |