123456789_123456789_123456789_123456789_123456789_

Class: Rails::Generators::AuthenticationGenerator

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base, Thor::Group
Instance Chain:
self, Base, Actions, Thor::Actions, Thor::Group
Inherits: Rails::Generators::Base
Defined in: railties/lib/rails/generators/rails/authentication/authentication_generator.rb

Class Attribute Summary

Base - Inherited

Class Method Summary

Base - Inherited

.base_root

Returns the base root for a common set of generators.

.default_source_root

Returns the default source root for a given generator.

.desc

Tries to get the description from a USAGE file one folder above the source root otherwise uses a default description.

.hide!

Convenience method to hide this generator from the available ones when running rails generator command.

.hook_for

Invoke a generator based on the value supplied by the user to the given option named “name”.

.namespace

Convenience method to get the namespace from the class name.

.remove_hook_for

Remove a previously added hook.

.source_root

Returns the source root for this generator using default_source_root as default.

.add_shebang_option!

Small macro to add ruby as an option to the generator with proper default value plus an instance helper method called shebang.

.banner

Use Rails default banner.

.base_name

Sets the base_name taking into account the current class namespace.

.default_aliases_for_option

Returns default aliases for the option name given doing a lookup in aliases.

.default_for_option

Returns default for the option name given doing a lookup in config.

.default_generator_root,
.default_value_for_option

Returns the default value for the option name given doing a lookup in options.

.generator_name

Removes the namespaces and get the generator name.

.usage_path,
.class_option

Make class option aware of options and aliases.

.inherited

Cache source root and add lib/generators/base/generator/templates to source paths.

.hooks

Keep hooks configuration that are used on prepare_for_invocation.

.prepare_for_invocation

Prepare class invocation to search on ::Rails namespace if a previous added hook is being used.

Instance Attribute Summary

Base - Inherited

Instance Method Summary

Base - Inherited

#class_collisions

Check whether the given class names are already taken by user application or Ruby on ::Rails.

#extract_last_module

Takes in an array of nested modules and extracts the last module.

#indent,
#module_namespacing

Wrap block with namespace of current application if namespace exists and is not skipped.

#namespace, #namespace_dirs, #namespaced_path, #wrap_with_namespace

Actions - Included

#add_source

Add the given source to Gemfile

#application
#environment

Adds configuration code to a Rails runtime environment.

#gem

Adds a gem declaration to the Gemfile for the specified gem.

#gem_group

Wraps gem entries inside a group.

#generate

Runs another generator.

#git

Runs one or more git commands.

#github,
#initializer

Creates an initializer file in config/initializers/.

#lib

Creates a file in lib/.

#rails_command

Runs the specified Rails command.

#rake

Runs the specified Rake task.

#rakefile

Creates a Rake tasks file in lib/tasks/.

#readme

Reads the given file at the source root and prints it in the console.

#route

Make an entry in Rails routing file config/routes.rb.

#vendor

Creates a file in vendor/.

#append_file_with_newline

Append string to a file with a newline if necessary.

#execute_command

Runs the supplied command using either “rake …” or “rails …” based on the executor parameter provided.

#indentation

Indent the Gemfile to the depth of @indentation.

#log

Define log for backwards compatibility.

#match_file,
#optimize_indentation

Returns optimized string with indentation.

#quote

Always returns value in double quotes.

#rebase_indentation
#route_namespace_pattern,
#with_indentation

Manage Gemfile indentation for a DSL action block.

#initialize

Instance Method Details

#add_migrations

[ GitHub ]

  
# File 'railties/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_controller

[ GitHub ]

  
# File 'railties/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_routes

[ GitHub ]

  
# File 'railties/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_files

[ GitHub ]

  
# File 'railties/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_bcrypt

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/authentication/authentication_generator.rb', line 41

def enable_bcrypt
  if File.read(File.expand_path("Gemfile", destination_root)).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