Class: Rails::Generators::AuthenticationGenerator

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

Overview

:nodoc:

Instance Method Summary collapse

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



50
51
52
53
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 50

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



32
33
34
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 32

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

#configure_authentication_routesObject



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

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

#create_authentication_filesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 13

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)

  template "app/mailers/passwords_mailer.rb"

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

  template "test/mailers/previews/passwords_mailer_preview.rb"
end

#enable_bcryptObject



41
42
43
44
45
46
47
48
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 41

def enable_bcrypt
  if File.read("Gemfile").include?('gem "bcrypt"')
    uncomment_lines "Gemfile", /gem "bcrypt"/
    Bundler.with_original_env { execute_command :bundle, "install --quiet" }
  else
    Bundler.with_original_env { execute_command :bundle, "add bcrypt", capture: true }
  end
end