diff options
Diffstat (limited to 'activerecord/lib/rails/generators')
4 files changed, 42 insertions, 42 deletions
diff --git a/activerecord/lib/rails/generators/active_record.rb b/activerecord/lib/rails/generators/active_record.rb index dc29213235..68fca44e3b 100644 --- a/activerecord/lib/rails/generators/active_record.rb +++ b/activerecord/lib/rails/generators/active_record.rb @@ -1,7 +1,7 @@ -require 'rails/generators/named_base' -require 'rails/generators/active_model' -require 'rails/generators/active_record/migration' -require 'active_record' +require "rails/generators/named_base" +require "rails/generators/active_model" +require "rails/generators/active_record/migration" +require "active_record" module ActiveRecord module Generators # :nodoc: diff --git a/activerecord/lib/rails/generators/active_record/migration.rb b/activerecord/lib/rails/generators/active_record/migration.rb index c2b2209638..4263c11ffc 100644 --- a/activerecord/lib/rails/generators/active_record/migration.rb +++ b/activerecord/lib/rails/generators/active_record/migration.rb @@ -1,4 +1,4 @@ -require 'rails/generators/migration' +require "rails/generators/migration" module ActiveRecord module Generators # :nodoc: diff --git a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb index de03550ec2..76182a3c24 100644 --- a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb +++ b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb @@ -1,10 +1,10 @@ -require 'rails/generators/active_record' -require 'active_support/core_ext/regexp' +require "rails/generators/active_record" +require "active_support/core_ext/regexp" module ActiveRecord module Generators # :nodoc: class MigrationGenerator < Base # :nodoc: - argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]" + argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]" class_option :primary_key_type, type: :string, desc: "The type for primary key" @@ -15,43 +15,43 @@ module ActiveRecord end protected - attr_reader :migration_action, :join_tables + attr_reader :migration_action, :join_tables # Sets the default migration template that is being used for the generation of the migration. # Depending on command line arguments, the migration template and the table name instance # variables are set up. - def set_local_assigns! - @migration_template = "migration.rb" - case file_name - when /^(add|remove)_.*_(?:to|from)_(.*)/ - @migration_action = $1 - @table_name = normalize_table_name($2) - when /join_table/ - if attributes.length == 2 - @migration_action = 'join' - @join_tables = pluralize_table_names? ? attributes.map(&:plural_name) : attributes.map(&:singular_name) + def set_local_assigns! + @migration_template = "migration.rb" + case file_name + when /^(add|remove)_.*_(?:to|from)_(.*)/ + @migration_action = $1 + @table_name = normalize_table_name($2) + when /join_table/ + if attributes.length == 2 + @migration_action = "join" + @join_tables = pluralize_table_names? ? attributes.map(&:plural_name) : attributes.map(&:singular_name) - set_index_names + set_index_names + end + when /^create_(.+)/ + @table_name = normalize_table_name($1) + @migration_template = "create_table_migration.rb" end - when /^create_(.+)/ - @table_name = normalize_table_name($1) - @migration_template = "create_table_migration.rb" end - end - def set_index_names - attributes.each_with_index do |attr, i| - attr.index_name = [attr, attributes[i - 1]].map{ |a| index_name_for(a) } + def set_index_names + attributes.each_with_index do |attr, i| + attr.index_name = [attr, attributes[i - 1]].map{ |a| index_name_for(a) } + end end - end - def index_name_for(attribute) - if attribute.foreign_key? - attribute.name - else - attribute.name.singularize.foreign_key - end.to_sym - end + def index_name_for(attribute) + if attribute.foreign_key? + attribute.name + else + attribute.name.singularize.foreign_key + end.to_sym + end private def attributes_with_index diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb index 0d72913258..f1ddc61688 100644 --- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb +++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb @@ -1,9 +1,9 @@ -require 'rails/generators/active_record' +require "rails/generators/active_record" module ActiveRecord module Generators # :nodoc: class ModelGenerator < Base # :nodoc: - argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]" + argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]" check_class_collision @@ -22,13 +22,13 @@ module ActiveRecord def create_model_file generate_application_record - template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") + template "model.rb", File.join("app/models", class_path, "#{file_name}.rb") end def create_module_file return if regular_class_path.empty? generate_application_record - template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke + template "module.rb", File.join("app/models", "#{class_path.join('/')}.rb") if behavior == :invoke end hook_for :test_framework @@ -42,13 +42,13 @@ module ActiveRecord # FIXME: Change this file to a symlink once RubyGems 2.5.0 is required. def generate_application_record if self.behavior == :invoke && !application_record_exist? - template 'application_record.rb', application_record_file_name + template "application_record.rb", application_record_file_name end end # Used by the migration template to determine the parent name of the model def parent_class_name - options[:parent] || 'ApplicationRecord' + options[:parent] || "ApplicationRecord" end def application_record_exist? @@ -61,7 +61,7 @@ module ActiveRecord @application_record_file_name ||= if mountable_engine? "app/models/#{namespaced_path}/application_record.rb" else - 'app/models/application_record.rb' + "app/models/application_record.rb" end end end |