提交 30d2627c 编写于 作者: A AvnerCohen

Another batch of hash syntax changes to comment, this time around, I tried to...

Another batch of hash syntax changes to comment, this time around, I tried to keep 'output' messages untouched.
上级 6004fd33
......@@ -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, <tt>Client < Company</tt> to do something
# like render <tt>:partial => @client.becomes(Company)</tt> to render that
# like render <tt>partial: @client.becomes(Company)</tt> 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
......
......@@ -81,13 +81,13 @@ def reflect_on_all_autosave_associations
class MacroReflection
# Returns the name of the macro.
#
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>:balance</tt>
# <tt>composed_of :balance, class_name: 'Money'</tt> returns <tt>:balance</tt>
# <tt>has_many :clients</tt> returns <tt>:clients</tt>
attr_reader :name
# Returns the macro type.
#
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>:composed_of</tt>
# <tt>composed_of :balance, class_name: 'Money'</tt> returns <tt>:composed_of</tt>
# <tt>has_many :clients</tt> returns <tt>:has_many</tt>
attr_reader :macro
......@@ -95,7 +95,7 @@ class MacroReflection
# Returns the hash of options used for the macro.
#
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>{ :class_name => "Money" }</tt>
# <tt>composed_of :balance, class_name: 'Money'</tt> returns <tt>{ class_name: "Money" }</tt>
# <tt>has_many :clients</tt> returns +{}+
attr_reader :options
......@@ -115,7 +115,7 @@ def initialize(macro, name, scope, options, active_record)
# Returns the class for the macro.
#
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns the Money class
# <tt>composed_of :balance, class_name: 'Money'</tt> returns the Money class
# <tt>has_many :clients</tt> returns the Client class
def klass
@klass ||= class_name.constantize
......@@ -123,7 +123,7 @@ def klass
# Returns the class name for the macro.
#
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>'Money'</tt>
# <tt>composed_of :balance, class_name: 'Money'</tt> returns <tt>'Money'</tt>
# <tt>has_many :clients</tt> returns <tt>'Client'</tt>
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
# <tt>:validate => false</tt>, validation will take place when:
# <tt>validate: false</tt>, validation will take place when:
#
# * you explicitly enable validation; <tt>:validate => true</tt>
# * you use autosave; <tt>:autosave => true</tt>
# * you explicitly enable validation; <tt>validate: true</tt>
# * you use autosave; <tt>autosave: true</tt>
# * 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
......
......@@ -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 <tt>before_*</tt> 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册