From 9edd4e18c411e6834569bbe7b6350f02342970d8 Mon Sep 17 00:00:00 2001 From: AvnerCohen Date: Tue, 23 Oct 2012 22:39:49 +0200 Subject: Migration of docs to 1.9 hash syntax --- .../lib/active_record/associations/preloader.rb | 6 +-- .../associations/through_association.rb | 2 +- .../abstract/database_statements.rb | 2 +- .../abstract/schema_definitions.rb | 42 +++++++++---------- .../abstract/schema_statements.rb | 48 +++++++++++----------- .../connection_adapters/abstract_mysql_adapter.rb | 4 +- .../connection_adapters/mysql2_adapter.rb | 2 +- .../postgresql/schema_statements.rb | 2 +- 8 files changed, 54 insertions(+), 54 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index c1cd3a4ae3..0848e7afb3 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -72,7 +72,7 @@ module ActiveRecord # books. # - a Hash which specifies multiple association names, as well as # association names for the to-be-preloaded association objects. For - # example, specifying { :author => :avatar } will preload a + # example, specifying { author: :avatar } will preload a # book's author, as well as that author's avatar. # # +:associations+ has the same format as the +:include+ option for @@ -80,8 +80,8 @@ module ActiveRecord # # :books # [ :books, :author ] - # { :author => :avatar } - # [ :books, { :author => :avatar } ] + # { author: :avatar } + # [ :books, { author: :avatar } ] def initialize(records, associations, preload_scope = nil) @records = Array.wrap(records).compact.uniq @associations = Array.wrap(associations) diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb index b9e014735b..43520142bf 100644 --- a/activerecord/lib/active_record/associations/through_association.rb +++ b/activerecord/lib/active_record/associations/through_association.rb @@ -28,7 +28,7 @@ module ActiveRecord # methods which create and delete records on the association. # # We only support indirectly modifying through associations which has a belongs_to source. - # This is the "has_many :tags, :through => :taggings" situation, where the join model + # This is the "has_many :tags, through: :taggings" situation, where the join model # typically has a belongs_to on both side. In other words, associations which could also # be represented as has_and_belongs_to_many associations. # diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 0d7046a705..4f3eebce7d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -150,7 +150,7 @@ module ActiveRecord # already-automatically-released savepoints: # # Model.connection.transaction do # BEGIN - # Model.connection.transaction(:requires_new => true) do # CREATE SAVEPOINT active_record_1 + # Model.connection.transaction(requires_new: true) do # CREATE SAVEPOINT active_record_1 # Model.connection.create_table(...) # # active_record_1 now automatically released # end # RELEASE SAVEPOINT active_record_1 <--- BOOM! database error! diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index dca355aa93..d61731633a 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -161,21 +161,21 @@ module ActiveRecord # td.column(:granted, :boolean) # # granted BOOLEAN # - # td.column(:picture, :binary, :limit => 2.megabytes) + # td.column(:picture, :binary, limit: 2.megabytes) # # => picture BLOB(2097152) # - # td.column(:sales_stage, :string, :limit => 20, :default => 'new', :null => false) + # td.column(:sales_stage, :string, limit: 20, default: 'new', null: false) # # => sales_stage VARCHAR(20) DEFAULT 'new' NOT NULL # - # td.column(:bill_gates_money, :decimal, :precision => 15, :scale => 2) + # td.column(:bill_gates_money, :decimal, precision: 15, scale: 2) # # => bill_gates_money DECIMAL(15,2) # - # td.column(:sensor_reading, :decimal, :precision => 30, :scale => 20) + # td.column(:sensor_reading, :decimal, precision: 30, scale: 20) # # => sensor_reading DECIMAL(30,20) # # # While :scale defaults to zero on most databases, it # # probably wouldn't hurt to include it. - # td.column(:huge_integer, :decimal, :precision => 30) + # td.column(:huge_integer, :decimal, precision: 30) # # => huge_integer DECIMAL(30) # # # Defines a column with a database-specific type. @@ -190,11 +190,11 @@ module ActiveRecord # # What can be written like this with the regular calls to column: # - # create_table "products", :force => true do |t| + # create_table "products", force: true do |t| # t.column "shop_id", :integer # t.column "creator_id", :integer - # t.column "name", :string, :default => "Untitled" - # t.column "value", :string, :default => "Untitled" + # t.column "name", :string, default: "Untitled" + # t.column "value", :string, default: "Untitled" # t.column "created_at", :datetime # t.column "updated_at", :datetime # end @@ -203,7 +203,7 @@ module ActiveRecord # # create_table :products do |t| # t.integer :shop_id, :creator_id - # t.string :name, :value, :default => "Untitled" + # t.string :name, :value, default: "Untitled" # t.timestamps # end # @@ -218,17 +218,17 @@ module ActiveRecord # create_table :taggings do |t| # t.integer :tag_id, :tagger_id, :taggable_id # t.string :tagger_type - # t.string :taggable_type, :default => 'Photo' + # t.string :taggable_type, default: 'Photo' # end - # add_index :taggings, :tag_id, :name => 'index_taggings_on_tag_id' + # add_index :taggings, :tag_id, name: 'index_taggings_on_tag_id' # add_index :taggings, [:tagger_id, :tagger_type] # # Can also be written as follows using references: # # create_table :taggings do |t| - # t.references :tag, :index => { :name => 'index_taggings_on_tag_id' } - # t.references :tagger, :polymorphic => true, :index => true - # t.references :taggable, :polymorphic => { :default => 'Photo' } + # t.references :tag, index: { name: 'index_taggings_on_tag_id' } + # t.references :tagger, polymorphic: true, index: true + # t.references :taggable, polymorphic: { default: 'Photo' } # end def column(name, type, options = {}) name = name.to_s @@ -262,7 +262,7 @@ module ActiveRecord # Adds index options to the indexes hash, keyed by column name # This is primarily used to track indexes that need to be created after the table # - # index(:account_id, :name => 'index_projects_on_account_id') + # index(:account_id, name: 'index_projects_on_account_id') def index(column_name, options = {}) indexes[column_name] = options end @@ -365,9 +365,9 @@ module ActiveRecord # ====== Creating a simple index # t.index(:name) # ====== Creating a unique index - # t.index([:branch_id, :party_id], :unique => true) + # t.index([:branch_id, :party_id], unique: true) # ====== Creating a named index - # t.index([:branch_id, :party_id], :unique => true, :name => 'by_branch_party') + # t.index([:branch_id, :party_id], unique: true, name: 'by_branch_party') def index(column_name, options = {}) @base.add_index(@table_name, column_name, options) end @@ -387,7 +387,7 @@ module ActiveRecord # Changes the column's definition according to the new options. # See TableDefinition#column for details of the options you can use. # - # t.change(:name, :string, :limit => 80) + # t.change(:name, :string, limit: 80) # t.change(:description, :text) def change(column_name, type, options = {}) @base.change_column(@table_name, column_name, type, options) @@ -414,11 +414,11 @@ module ActiveRecord # ====== Remove the index_table_name_on_column in the table_name table # t.remove_index :column # ====== Remove the index named index_table_name_on_branch_id in the table_name table - # t.remove_index :column => :branch_id + # t.remove_index column: :branch_id # ====== Remove the index named index_table_name_on_branch_id_and_party_id in the table_name table - # t.remove_index :column => [:branch_id, :party_id] + # t.remove_index column: [:branch_id, :party_id] # ====== Remove the index named by_branch_party in the table_name table - # t.remove_index :name => :by_branch_party + # t.remove_index name: :by_branch_party def remove_index(options = {}) @base.remove_index(@table_name, options) end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 86d6266af9..8790518d37 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -36,10 +36,10 @@ module ActiveRecord # index_exists?(:suppliers, [:company_id, :company_type]) # # # Check a unique index exists - # index_exists?(:suppliers, :company_id, :unique => true) + # index_exists?(:suppliers, :company_id, unique: true) # # # Check an index with a custom name exists - # index_exists?(:suppliers, :company_id, :name => "idx_company_id" + # index_exists?(:suppliers, :company_id, name: "idx_company_id" def index_exists?(table_name, column_name, options = {}) column_names = Array(column_name) index_name = options.key?(:name) ? options[:name].to_s : index_name(table_name, :column => column_names) @@ -89,14 +89,14 @@ module ActiveRecord # # table. # # create_table(:suppliers) do |t| - # t.column :name, :string, :limit => 60 + # t.column :name, :string, limit: 60 # # Other fields here # end # # === Block form, with shorthand # # You can also use the column types as method calls, rather than calling the column method. # create_table(:suppliers) do |t| - # t.string :name, :limit => 60 + # t.string :name, limit: 60 # # Other fields here # end # @@ -104,7 +104,7 @@ module ActiveRecord # # Creates a table called 'suppliers' with no columns. # create_table(:suppliers) # # Add a column to 'suppliers'. - # add_column(:suppliers, :name, :string, {:limit => 60}) + # add_column(:suppliers, :name, :string, {limit: 60}) # # The +options+ hash can include the following keys: # [:id] @@ -127,15 +127,15 @@ module ActiveRecord # Defaults to false. # # ====== Add a backend specific option to the generated SQL (MySQL) - # create_table(:suppliers, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8') + # create_table(:suppliers, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8') # generates: # CREATE TABLE suppliers ( # id int(11) DEFAULT NULL auto_increment PRIMARY KEY # ) ENGINE=InnoDB DEFAULT CHARSET=utf8 # # ====== Rename the primary key column - # create_table(:objects, :primary_key => 'guid') do |t| - # t.column :name, :string, :limit => 80 + # create_table(:objects, primary_key: 'guid') do |t| + # t.column :name, :string, limit: 80 # end # generates: # CREATE TABLE objects ( @@ -144,7 +144,7 @@ module ActiveRecord # ) # # ====== Do not add a primary key column - # create_table(:categories_suppliers, :id => false) do |t| + # create_table(:categories_suppliers, id: false) do |t| # t.column :category_id, :integer # t.column :supplier_id, :integer # end @@ -193,7 +193,7 @@ module ActiveRecord # Defaults to false. # # ====== Add a backend specific option to the generated SQL (MySQL) - # create_join_table(:assemblies, :parts, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8') + # create_join_table(:assemblies, :parts, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8') # generates: # CREATE TABLE assemblies_parts ( # assembly_id int NOT NULL, @@ -218,7 +218,7 @@ module ActiveRecord # # # change_table() yields a Table instance # change_table(:suppliers) do |t| - # t.column :name, :string, :limit => 60 + # t.column :name, :string, limit: 60 # # Other column alterations here # end # @@ -231,12 +231,12 @@ module ActiveRecord # # ====== Add a column # change_table(:suppliers) do |t| - # t.column :name, :string, :limit => 60 + # t.column :name, :string, limit: 60 # end # # ====== Add 2 integer columns # change_table(:suppliers) do |t| - # t.integer :width, :height, :null => false, :default => 0 + # t.integer :width, :height, null: false, default: 0 # end # # ====== Add created_at/updated_at columns @@ -253,7 +253,7 @@ module ActiveRecord # # ====== Add a polymorphic foreign key column # change_table(:suppliers) do |t| - # t.belongs_to :company, :polymorphic => true + # t.belongs_to :company, polymorphic: true # end # # Creates company_type(varchar) and company_id(integer) columns @@ -318,7 +318,7 @@ module ActiveRecord # Changes the column's definition according to the new options. # See TableDefinition#column for details of the options you can use. # - # change_column(:suppliers, :name, :string, :limit => 80) + # change_column(:suppliers, :name, :string, limit: 80) # change_column(:accounts, :description, :text) def change_column(table_name, column_name, type, options = {}) raise NotImplementedError, "change_column is not implemented" @@ -352,35 +352,35 @@ module ActiveRecord # CREATE INDEX suppliers_name_index ON suppliers(name) # # ====== Creating a unique index - # add_index(:accounts, [:branch_id, :party_id], :unique => true) + # add_index(:accounts, [:branch_id, :party_id], unique: true) # generates # CREATE UNIQUE INDEX accounts_branch_id_party_id_index ON accounts(branch_id, party_id) # # ====== Creating a named index - # add_index(:accounts, [:branch_id, :party_id], :unique => true, :name => 'by_branch_party') + # add_index(:accounts, [:branch_id, :party_id], unique: true, name: 'by_branch_party') # generates # CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id) # # ====== Creating an index with specific key length - # add_index(:accounts, :name, :name => 'by_name', :length => 10) + # add_index(:accounts, :name, name: 'by_name', length: 10) # generates # CREATE INDEX by_name ON accounts(name(10)) # - # add_index(:accounts, [:name, :surname], :name => 'by_name_surname', :length => {:name => 10, :surname => 15}) + # add_index(:accounts, [:name, :surname], name: 'by_name_surname', length: {name: 10, surname: 15}) # generates # CREATE INDEX by_name_surname ON accounts(name(10), surname(15)) # # Note: SQLite doesn't support index length # # ====== Creating an index with a sort order (desc or asc, asc is the default) - # add_index(:accounts, [:branch_id, :party_id, :surname], :order => {:branch_id => :desc, :party_id => :asc}) + # add_index(:accounts, [:branch_id, :party_id, :surname], order: {branch_id: :desc, party_id: :asc}) # generates # CREATE INDEX by_branch_desc_party ON accounts(branch_id DESC, party_id ASC, surname) # # Note: mysql doesn't yet support index order (it accepts the syntax but ignores it) # # ====== Creating a partial index - # add_index(:accounts, [:branch_id, :party_id], :unique => true, :where => "active") + # add_index(:accounts, [:branch_id, :party_id], unique: true, where: "active") # generates # CREATE UNIQUE INDEX index_accounts_on_branch_id_and_party_id ON accounts(branch_id, party_id) WHERE active # @@ -396,11 +396,11 @@ module ActiveRecord # Remove the index_accounts_on_column in the accounts table. # remove_index :accounts, :column # Remove the index named index_accounts_on_branch_id in the accounts table. - # remove_index :accounts, :column => :branch_id + # remove_index :accounts, column: :branch_id # Remove the index named index_accounts_on_branch_id_and_party_id in the accounts table. - # remove_index :accounts, :column => [:branch_id, :party_id] + # remove_index :accounts, column: [:branch_id, :party_id] # Remove the index named by_branch_party in the accounts table. - # remove_index :accounts, :name => :by_branch_party + # remove_index :accounts, name: :by_branch_party def remove_index(table_name, options = {}) remove_index!(table_name, index_name_for_remove(table_name, options)) end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index b0e7bd7e82..7da77af3a9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -353,9 +353,9 @@ module ActiveRecord # Charset defaults to utf8. # # Example: - # create_database 'charset_test', :charset => 'latin1', :collation => 'latin1_bin' + # create_database 'charset_test', charset: 'latin1', collation: 'latin1_bin' # create_database 'matt_development' - # create_database 'matt_development', :charset => :big5 + # create_database 'matt_development', charset: :big5 def create_database(name, options = {}) if options[:collation] execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{options[:charset] || 'utf8'}` COLLATE `#{options[:collation]}`" diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 879eec7fcf..f55d19393c 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -175,7 +175,7 @@ module ActiveRecord # # as values. # def select_one(sql, name = nil) # result = execute(sql, name) - # result.each(:as => :hash) do |r| + # result.each(as: :hash) do |r| # return r # end # end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 7cad8f94cf..82a0b662f4 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -16,7 +16,7 @@ module ActiveRecord # # Example: # create_database config[:database], config - # create_database 'foo_development', :encoding => 'unicode' + # create_database 'foo_development', encoding: 'unicode' def create_database(name, options = {}) options = options.reverse_merge(:encoding => "utf8") -- cgit v1.2.3