class AutoAuth::InstallGenerator
Public Class Methods
source_root()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 8 def self.source_root File.expand_path(File.join(File.dirname(__FILE__), "..", "templates")) end
Public Instance Methods
add_gems()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 25 def add_gems gem "bcrypt" gem "responders" end
create_controller_files()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 37 def create_controller_files template "controllers/sessions_controller.rb", "app/controllers/sessions_controller.rb" template "controllers/passwords_controller.rb", "app/controllers/passwords_controller.rb" template "controllers/registrations_controller.rb", "app/controllers/registrations_controller.rb" end
create_mailer_files()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 43 def create_mailer_files template "mailers/identity_mailer.rb", "app/mailers/#{identity_model}_mailer.rb" template "views/mailers/reset_password.html.erb", "app/views/#{identity_model}_mailer/reset_password.html.erb" template "views/mailers/confirm_email.html.erb", "app/views/#{identity_model}_mailer/confirm_email.html.erb" end
create_migration_files()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 64 def create_migration_files migration_template "migration.rb", "db/migrate/create_#{domain_model}_and_#{identity_model}.rb" end
create_model_files()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 30 def create_model_files template "models/domain_model.rb", "app/models/#{domain_model}.rb" template "models/identity_model.rb", "app/models/#{identity_model}.rb" template "models/registration.rb", "app/models/registration.rb" template "models/concerns/token_verification.rb", "app/models/concerns/token_verification.rb" end
create_routes()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 50 def create_routes route <<-REGISTRATION_ROUTE resources :registrations, only: [:create] do get :confirm, on: :collection end REGISTRATION_ROUTE route "resources :passwords, only: [:edit, :create, :update]" route "resources :sessions, only: [:create]" route "get :forgot_password, to: 'passwords#new'" route "get :sign_up, to: 'registrations#new'" route "get :sign_out, to: 'sessions#destroy'" route "get :sign_in, to: 'sessions#new'" end
create_view_files()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 90 def create_view_files template "views/sessions/new.html.erb", "app/views/sessions/new.html.erb" template "views/passwords/new.html.erb", "app/views/passwords/new.html.erb" template "views/passwords/edit.html.erb", "app/views/passwords/edit.html.erb" template "views/registrations/new.html.erb", "app/views/registrations/new.html.erb" template "config/locales/auto_auth.en.yml", "config/locales/auto_auth.en.yml" end
include_authentication()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 68 def include_authentication template "controllers/concerns/authentication.rb", "app/controllers/concerns/authentication.rb" inject_into_file "app/controllers/application_controller.rb", after: /protect_from_forgery.*$/ do <<-AUTOAUTH include Authentication before_action :authenticate! rescue_from ActiveSupport::MessageVerifier::InvalidSignature, with: :handle_invalid_signature private def handle_invalid_signature redirect_to(root_path, alert: t(:'auto_auth.application.invalid_signature')) end AUTOAUTH end end
Private Instance Methods
domain_model()
click to toggle source
Domain model helpers
# File lib/generators/auto_auth/install_generator.rb, line 106 def domain_model @domain_model ||= options.domain_model.underscore end
domain_model_class()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 110 def domain_model_class @domain_model_class ||= domain_model.classify end
domain_model_id()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 114 def domain_model_id @domain_model_id ||= "#{domain_model}_id" end
identity_mailer_class()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 137 def identity_mailer_class @identity_mailer_class ||= "#{identity_model_class}Mailer".classify end
identity_model()
click to toggle source
Identity Model Helpers
# File lib/generators/auto_auth/install_generator.rb, line 125 def identity_model @identity_model ||= options.identity_model.underscore end
identity_model_class()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 129 def identity_model_class @identity_model_class ||= identity_model.classify end
plural_domain_model()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 118 def plural_domain_model @plural_domain_model ||= domain_model.pluralize end
plural_identity_model()
click to toggle source
# File lib/generators/auto_auth/install_generator.rb, line 133 def plural_identity_model @plural_identity_model ||= identity_model.pluralize end