From 30d2627cff29252efe4d711bb9d9bc2b1719293c Mon Sep 17 00:00:00 2001 From: AvnerCohen Date: Tue, 23 Oct 2012 13:02:34 +0200 Subject: [PATCH] Another batch of hash syntax changes to comment, this time around, I tried to keep 'output' messages untouched. --- activerecord/lib/active_record/persistence.rb | 18 +++++++------- activerecord/lib/active_record/reflection.rb | 24 +++++++++---------- activerecord/lib/active_record/relation.rb | 10 ++++---- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 611d3d97c3..65a31f1566 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -15,18 +15,18 @@ module ClassMethods # # ==== Examples # # Create a single new object - # User.create(:first_name => 'Jamie') + # User.create(first_name: 'Jamie') # # # Create an Array of new objects - # User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }]) + # User.create([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) # # # Create a single object and pass it into a block to set other attributes. - # User.create(:first_name => 'Jamie') do |u| + # User.create(first_name: 'Jamie') do |u| # u.is_admin = false # end # # # Creating an Array of new objects using a block, where the block is executed for each object: - # User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }]) do |u| + # User.create([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) do |u| # u.is_admin = false # end def create(attributes = nil, &block) @@ -64,7 +64,7 @@ def persisted? # # By default, save always run validations. If any of them fail the action # is cancelled and +save+ returns +false+. However, if you supply - # :validate => false, validations are bypassed altogether. See + # validate: false, validations are bypassed altogether. See # ActiveRecord::Validations for more information. # # There's a series of callbacks associated with +save+. If any of the @@ -143,7 +143,7 @@ def destroy! # inheritance structures where you want a subclass to appear as the # superclass. This can be used along with record identification in # Action Pack to allow, say, Client < Company to do something - # like render :partial => @client.becomes(Company) to render that + # like render partial: @client.becomes(Company) to render that # instance using the companies/company partial instead of clients/client. # # Note: The new instance will share a link to the same attributes as the original class. @@ -284,7 +284,7 @@ def toggle!(attribute) # Reloads the attributes of this object from the database. # The optional options argument is passed to find when reloading so you - # may do e.g. record.reload(:lock => true) to reload the same record with + # may do e.g. record.reload(lock: true) to reload the same record with # an exclusive row lock. def reload(options = nil) clear_aggregation_cache @@ -315,11 +315,11 @@ def reload(options = nil) # If used along with +belongs_to+ then +touch+ will invoke +touch+ method on associated object. # # class Brake < ActiveRecord::Base - # belongs_to :car, :touch => true + # belongs_to :car, touch: true # end # # class Car < ActiveRecord::Base - # belongs_to :corporation, :touch => true + # belongs_to :corporation, touch: true # end # # # triggers @brake.car.touch and @brake.car.corporation.touch diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index f322b96f79..0103de4cbd 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -81,13 +81,13 @@ def reflect_on_all_autosave_associations class MacroReflection # Returns the name of the macro. # - # composed_of :balance, :class_name => 'Money' returns :balance + # composed_of :balance, class_name: 'Money' returns :balance # has_many :clients returns :clients attr_reader :name # Returns the macro type. # - # composed_of :balance, :class_name => 'Money' returns :composed_of + # composed_of :balance, class_name: 'Money' returns :composed_of # has_many :clients returns :has_many attr_reader :macro @@ -95,7 +95,7 @@ class MacroReflection # Returns the hash of options used for the macro. # - # composed_of :balance, :class_name => 'Money' returns { :class_name => "Money" } + # composed_of :balance, class_name: 'Money' returns { class_name: "Money" } # has_many :clients returns +{}+ attr_reader :options @@ -115,7 +115,7 @@ def initialize(macro, name, scope, options, active_record) # Returns the class for the macro. # - # composed_of :balance, :class_name => 'Money' returns the Money class + # composed_of :balance, class_name: 'Money' returns the Money class # has_many :clients returns the Client class def klass @klass ||= class_name.constantize @@ -123,7 +123,7 @@ def klass # Returns the class name for the macro. # - # composed_of :balance, :class_name => 'Money' returns 'Money' + # composed_of :balance, class_name: 'Money' returns 'Money' # has_many :clients returns 'Client' def class_name @class_name ||= (options[:class_name] || derive_class_name).to_s @@ -315,10 +315,10 @@ def collection? # the parent's validation. # # Unless you explicitly disable validation with - # :validate => false, validation will take place when: + # validate: false, validation will take place when: # - # * you explicitly enable validation; :validate => true - # * you use autosave; :autosave => true + # * you explicitly enable validation; validate: true + # * you use autosave; autosave: true # * the association is a +has_many+ association def validate? !options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many) @@ -399,7 +399,7 @@ class ThroughReflection < AssociationReflection #:nodoc: # # class Post < ActiveRecord::Base # has_many :taggings - # has_many :tags, :through => :taggings + # has_many :tags, through: :taggings # end # def source_reflection @@ -411,7 +411,7 @@ def source_reflection # # class Post < ActiveRecord::Base # has_many :taggings - # has_many :tags, :through => :taggings + # has_many :tags, through: :taggings # end # # tags_reflection = Post.reflect_on_association(:tags) @@ -439,12 +439,12 @@ def chain # # class Person # has_many :articles - # has_many :comment_tags, :through => :articles + # has_many :comment_tags, through: :articles # end # # class Article # has_many :comments - # has_many :comment_tags, :through => :comments, :source => :tags + # has_many :comment_tags, through: :comments, source: :tags # end # # class Comment diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 2e2286e4fd..cb9cc5a9df 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -235,7 +235,7 @@ def many? # Scope all queries to the current scope. # - # Comment.where(:post_id => 1).scoping do + # Comment.where(post_id: 1).scoping do # Comment.first # SELECT * FROM comments WHERE post_id = 1 # end # @@ -266,7 +266,7 @@ def scoping # Book.where('title LIKE ?', '%Rails%').update_all(author: 'David') # # # Update all books that match conditions, but limit it to 5 ordered by date - # Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(:author => 'David') + # Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(author: 'David') def update_all(updates) raise ArgumentError, "Empty list of attributes to change" if updates.blank? @@ -339,7 +339,7 @@ def update(id, attributes) # # Person.destroy_all("last_login < '2004-04-04'") # Person.destroy_all(status: "inactive") - # Person.where(:age => 0..18).destroy_all + # Person.where(age: 0..18).destroy_all def destroy_all(conditions = nil) if conditions where(conditions).destroy_all @@ -384,7 +384,7 @@ def destroy(id) # # Post.delete_all("person_id = 5 AND (category = 'Something' OR category = 'Else')") # Post.delete_all(["person_id = ? AND (category = ? OR category = ?)", 5, 'Something', 'Else']) - # Post.where(:person_id => 5).where(:category => ['Something', 'Else']).delete_all + # Post.where(person_id: 5).where(category: ['Something', 'Else']).delete_all # # Both calls delete the affected posts all at once with a single DELETE statement. # If you need to destroy dependent associations or call your before_* or @@ -514,7 +514,7 @@ def eager_loading? # Joins that are also marked for preloading. In which case we should just eager load them. # Note that this is a naive implementation because we could have strings and symbols which # represent the same association, but that aren't matched by this. Also, we could have - # nested hashes which partially match, e.g. { :a => :b } & { :a => [:b, :c] } + # nested hashes which partially match, e.g. { a: :b } & { a: [:b, :c] } def joined_includes_values includes_values & joins_values end -- GitLab