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



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

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



30
31
32
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 30

def configure_application_controller
  gsub_file "app/controllers/application_controller.rb", /(class ApplicationController < ActionController::Base)/, "\\1\n  include Authentication"
end

#configure_authentication_routesObject



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

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
# File 'lib/rails/generators/rails/authentication/authentication_generator.rb', line 13

def create_authentication_files
  template "models/session.rb", File.join("app/models/session.rb")
  template "models/user.rb", File.join("app/models/user.rb")
  template "models/current.rb", File.join("app/models/current.rb")

  template "controllers/sessions_controller.rb", File.join("app/controllers/sessions_controller.rb")
  template "controllers/concerns/authentication.rb", File.join("app/controllers/concerns/authentication.rb")
  template "controllers/passwords_controller.rb", File.join("app/controllers/passwords_controller.rb")

  template "mailers/passwords_mailer.rb", File.join("app/mailers/passwords_mailer.rb")

  template "views/passwords_mailer/reset.html.erb", File.join("app/views/passwords_mailer/reset.html.erb")
  template "views/passwords_mailer/reset.text.erb", File.join("app/views/passwords_mailer/reset.text.erb")

  template "test/mailers/previews/passwords_mailer_preview.rb", File.join("test/mailers/previews/passwords_mailer_preview.rb")
end

#enable_bcryptObject



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

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 --quiet" }
  end
end