class ActiveRecord::Generators::AuthenticatableGenerator

Public Instance Methods

add_route() click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/generators/active_record/authenticatable_generator.rb, line 39
def add_route
  route_content = "authenticatable :#{plural_name}"
  route route_content
end
copy_authenticatable_migration() click to toggle source
# File lib/generators/active_record/authenticatable_generator.rb, line 14
def copy_authenticatable_migration
  if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
    migration_template "migration_existing.tt", "#{db_migrate_path}/add_authenticatable_to_#{table_name}.rb",
                       migration_version: migration_version
  else
    migration_template "migration.tt", "#{db_migrate_path}/authenticatable_create_#{table_name}.rb",
                       migration_version: migration_version
  end
end
generate_model() click to toggle source
# File lib/generators/active_record/authenticatable_generator.rb, line 24
def generate_model
  invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
end
inject_authenticatable() click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/generators/active_record/authenticatable_generator.rb, line 29
def inject_authenticatable
  content = model_contents
  class_path = (namespaced? ? class_name.to_s.split("::") : [class_name])
  indent_depth = class_path.size - 1
  content = content.split("\n").map { |line| ("  " * indent_depth) + line }.join("\n") << "\n"

  inject_into_class(model_path, class_path.last, content) if model_exists?
end

Private Instance Methods

migration_data() click to toggle source

rubocop:disable Layout/IndentationWidth

# File lib/generators/active_record/authenticatable_generator.rb, line 51
      def migration_data
<<RUBY
      ## Authenticatable
      t.string :email, null: false, default: ""
      t.string :password_digest, null: false, default: ""
      t.string :reset_password_token, null: false, default: ""
      t.datetime :reset_password_sent_at
RUBY
      end
model_contents() click to toggle source
# File lib/generators/active_record/authenticatable_generator.rb, line 46
def model_contents
  "  authenticatable\n"
end