Class: Rails::Generators::AuthenticationGenerator

Inherits:
Base
  • Object
show all
Includes:
BundleHelper
Defined in:
lib/rails/generators/rails/authentication/authentication_generator.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from BundleHelper

#bundle_command

Methods inherited from Base

base_root, class_option, default_source_root, desc, exit_on_failure?, hide!, hook_for, inherited, namespace, remove_hook_for, source_root

Methods included from Actions

#add_source, #environment, #gem, #gem_group, #generate, #git, #github, #initialize, #initializer, #lib, #rails_command, #rake, #rakefile, #readme, #route, #vendor

Instance Method Details

#add_migrationsObject



54
55
56
57
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 54

def add_migrations
  generate "migration", "CreateUsers", "email_address:string!:uniq password_digest:string!", "--force"
  generate "migration", "CreateSessions", "user:references ip_address:string user_agent:string", "--force"
end

#configure_application_controllerObject



36
37
38
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 36

def configure_application_controller
  inject_into_class "app/controllers/application_controller.rb", "ApplicationController", "  include Authentication\n"
end

#configure_authentication_routesObject



40
41
42
43
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 40

def configure_authentication_routes
  route "resources :passwords, param: :token"
  route "resource :session"
end

#create_authentication_filesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 17

def create_authentication_files
  template "app/models/session.rb"
  template "app/models/user.rb"
  template "app/models/current.rb"

  template "app/controllers/sessions_controller.rb"
  template "app/controllers/concerns/authentication.rb"
  template "app/controllers/passwords_controller.rb"

  template "app/channels/application_cable/connection.rb" if defined?(ActionCable::Engine)

  if defined?(ActionMailer::Railtie)
    template "app/mailers/passwords_mailer.rb"

    template "app/views/passwords_mailer/reset.html.erb"
    template "app/views/passwords_mailer/reset.text.erb"
  end
end

#enable_bcryptObject



45
46
47
48
49
50
51
52
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 45

def enable_bcrypt
  if File.read(File.expand_path("Gemfile", destination_root)).include?('gem "bcrypt"')
    uncomment_lines "Gemfile", /gem "bcrypt"/
    bundle_command("install --quiet")
  else
    bundle_command("add bcrypt", {}, quiet: true)
  end
end