Permalink
Browse files

convert comments to 1.9 hash syntax

  • Loading branch information...
1 parent 01e38d8 commit 77eb1fb22d0f25183eb608b8ae55d9f1eb8bec59 @AvnerCohen AvnerCohen committed Oct 22, 2012
View
22 activemodel/lib/active_model/errors.rb
@@ -92,7 +92,7 @@ def clear
# Returns +true+ if the error messages include an error for the given key
# +attribute+, +false+ otherwise.
#
- # person.errors.messages # => { :name => ["can not be nil"] }
+ # person.errors.messages # => { name: ["can not be nil"] }
# person.errors.include?(:name) # => true
# person.errors.include?(:age) # => false
def include?(attribute)
@@ -103,7 +103,7 @@ def include?(attribute)
# Get messages for +key+.
#
- # person.errors.messages # => { :name => ["can not be nil"] }
+ # person.errors.messages # => { name: ["can not be nil"] }
# person.errors.get(:name) # => ["can not be nil"]
# person.errors.get(:age) # => nil
def get(key)
@@ -177,15 +177,15 @@ def size
# Returns all message values.
#
- # person.errors.messages # => { :name => ["can not be nil", "must be specified"] }
+ # person.errors.messages # => { name: ["can not be nil", "must be specified"] }
# person.errors.values # => [["can not be nil", "must be specified"]]
def values
messages.values
end
# Returns all message keys.
#
- # person.errors.messages # => { :name => ["can not be nil", "must be specified"] }
+ # person.errors.messages # => { name: ["can not be nil", "must be specified"] }
# person.errors.keys # => [:name]
def keys
messages.keys
@@ -240,17 +240,17 @@ def to_xml(options={})
# object. You can pass the <tt>:full_messages</tt> option. This determines
# if the json object should contain full messages or not (false by default).
#
- # person.as_json # => { :name => ["can not be nil"] }
- # person.as_json(full_messages: true) # => { :name => ["name can not be nil"] }
+ # person.as_json # => { name: ["can not be nil"] }
+ # person.as_json(full_messages: true) # => { name: ["name can not be nil"] }
def as_json(options=nil)
to_hash(options && options[:full_messages])
end
# Returns a Hash of attributes with their error messages. If +full_messages+
# is +true+, it will contain full messages (see +full_message+).
#
- # person.to_hash # => { :name => ["can not be nil"] }
- # person.to_hash(true) # => { :name => ["name can not be nil"] }
+ # person.to_hash # => { name: ["can not be nil"] }
+ # person.to_hash(true) # => { name: ["name can not be nil"] }
def to_hash(full_messages = false)
if full_messages
messages = {}
@@ -273,7 +273,7 @@ def to_hash(full_messages = false)
# # => ["is invalid", "must be implemented"]
#
# person.errors.messages
- # # => { :name => ["must be implemented", "is invalid"] }
+ # # => { name: ["must be implemented", "is invalid"] }
#
# If +message+ is a symbol, it will be translated using the appropriate
# scope (see +generate_message+).
@@ -306,7 +306,7 @@ def add(attribute, message = nil, options = {})
#
# person.errors.add_on_empty(:name)
# person.errors.messages
- # # => { :name => ["can't be empty"] }
+ # # => { name: ["can't be empty"] }
def add_on_empty(attributes, options = {})
[attributes].flatten.each do |attribute|
value = @base.send(:read_attribute_for_validation, attribute)
@@ -320,7 +320,7 @@ def add_on_empty(attributes, options = {})
#
# person.errors.add_on_blank(:name)
# person.errors.messages
- # # => { :name => ["can't be blank"] }
+ # # => { name: ["can't be blank"] }
def add_on_blank(attributes, options = {})
[attributes].flatten.each do |attribute|
value = @base.send(:read_attribute_for_validation, attribute)
View
10 activemodel/lib/active_model/validations.rb
@@ -33,7 +33,7 @@ module ActiveModel
# person.first_name = 'zoolander'
# person.valid? # => false
# person.invalid? # => true
- # person.errors.messages # => {:first_name=>["starts with z."]}
+ # person.errors.messages # => {first_name:["starts with z."]}
#
# Note that <tt>ActiveModel::Validations</tt> automatically adds an +errors+
# method to your instances initialized with a new <tt>ActiveModel::Errors</tt>
@@ -165,8 +165,8 @@ def validate(*args, &block)
# Person.validators
# # => [
# # #<MyValidator:0x007fbff403e808 @options={}>,
- # # #<OtherValidator:0x007fbff403d930 @options={:on=>:create}>,
- # # #<StrictValidator:0x007fbff3204a30 @options={:strict=>true}>
+ # # #<OtherValidator:0x007fbff403d930 @options={on: :create}>,
+ # # #<StrictValidator:0x007fbff3204a30 @options={strict:true}>
# # ]
def validators
_validators.values.flatten.uniq
@@ -186,7 +186,7 @@ def validators
# Person.validators_on(:name)
# # => [
# # #<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>,
- # # #<ActiveModel::Validations::InclusionValidator:0x007fe603bb8780 @attributes=[:age], @options={:in=>0..99}>
+ # # #<ActiveModel::Validations::InclusionValidator:0x007fe603bb8780 @attributes=[:age], @options={in:0..99}>
# # ]
def validators_on(*attributes)
attributes.flat_map do |attribute|
@@ -234,7 +234,7 @@ def initialize_dup(other) #:nodoc:
#
# person = Person.new
# person.valid? # => false
- # person.errors # => #<ActiveModel::Errors:0x007fe603816640 @messages={:name=>["can't be blank"]}>
+ # person.errors # => #<ActiveModel::Errors:0x007fe603816640 @messages={name:["can't be blank"]}>
def errors
@errors ||= Errors.new(self)
end
View
2 activemodel/lib/active_model/validator.rb
@@ -76,7 +76,7 @@ module ActiveModel
# include ActiveModel::Validations
# attr_accessor :title
#
- # validates :title, :presence => true
+ # validates :title, presence: true
# end
#
# Validator may also define a +setup+ instance method which will get called
View
24 activemodel/test/cases/validations/i18n_generate_message_validation_test.rb
@@ -8,7 +8,7 @@ def setup
@person = Person.new
end
- # validates_inclusion_of: generate_message(attr_name, :inclusion, :message => custom_message, :value => value)
+ # validates_inclusion_of: generate_message(attr_name, :inclusion, message: custom_message, value: value)
def test_generate_message_inclusion_with_default_message
assert_equal 'is not included in the list', @person.errors.generate_message(:title, :inclusion, :value => 'title')
end
@@ -17,7 +17,7 @@ def test_generate_message_inclusion_with_custom_message
assert_equal 'custom message title', @person.errors.generate_message(:title, :inclusion, :message => 'custom message %{value}', :value => 'title')
end
- # validates_exclusion_of: generate_message(attr_name, :exclusion, :message => custom_message, :value => value)
+ # validates_exclusion_of: generate_message(attr_name, :exclusion, message: custom_message, value: value)
def test_generate_message_exclusion_with_default_message
assert_equal 'is reserved', @person.errors.generate_message(:title, :exclusion, :value => 'title')
end
@@ -26,7 +26,7 @@ def test_generate_message_exclusion_with_custom_message
assert_equal 'custom message title', @person.errors.generate_message(:title, :exclusion, :message => 'custom message %{value}', :value => 'title')
end
- # validates_format_of: generate_message(attr_name, :invalid, :message => custom_message, :value => value)
+ # validates_format_of: generate_message(attr_name, :invalid, message: custom_message, value: value)
def test_generate_message_invalid_with_default_message
assert_equal 'is invalid', @person.errors.generate_message(:title, :invalid, :value => 'title')
end
@@ -35,7 +35,7 @@ def test_generate_message_invalid_with_custom_message
assert_equal 'custom message title', @person.errors.generate_message(:title, :invalid, :message => 'custom message %{value}', :value => 'title')
end
- # validates_confirmation_of: generate_message(attr_name, :confirmation, :message => custom_message)
+ # validates_confirmation_of: generate_message(attr_name, :confirmation, message: custom_message)
def test_generate_message_confirmation_with_default_message
assert_equal "doesn't match Title", @person.errors.generate_message(:title, :confirmation)
end
@@ -44,7 +44,7 @@ def test_generate_message_confirmation_with_custom_message
assert_equal 'custom message', @person.errors.generate_message(:title, :confirmation, :message => 'custom message')
end
- # validates_acceptance_of: generate_message(attr_name, :accepted, :message => custom_message)
+ # validates_acceptance_of: generate_message(attr_name, :accepted, message: custom_message)
def test_generate_message_accepted_with_default_message
assert_equal "must be accepted", @person.errors.generate_message(:title, :accepted)
end
@@ -53,7 +53,7 @@ def test_generate_message_accepted_with_custom_message
assert_equal 'custom message', @person.errors.generate_message(:title, :accepted, :message => 'custom message')
end
- # add_on_empty: generate_message(attr, :empty, :message => custom_message)
+ # add_on_empty: generate_message(attr, :empty, message: custom_message)
def test_generate_message_empty_with_default_message
assert_equal "can't be empty", @person.errors.generate_message(:title, :empty)
end
@@ -62,7 +62,7 @@ def test_generate_message_empty_with_custom_message
assert_equal 'custom message', @person.errors.generate_message(:title, :empty, :message => 'custom message')
end
- # add_on_blank: generate_message(attr, :blank, :message => custom_message)
+ # add_on_blank: generate_message(attr, :blank, message: custom_message)
def test_generate_message_blank_with_default_message
assert_equal "can't be blank", @person.errors.generate_message(:title, :blank)
end
@@ -71,7 +71,7 @@ def test_generate_message_blank_with_custom_message
assert_equal 'custom message', @person.errors.generate_message(:title, :blank, :message => 'custom message')
end
- # validates_length_of: generate_message(attr, :too_long, :message => custom_message, :count => option_value.end)
+ # validates_length_of: generate_message(attr, :too_long, message: custom_message, count: option_value.end)
def test_generate_message_too_long_with_default_message
assert_equal "is too long (maximum is 10 characters)", @person.errors.generate_message(:title, :too_long, :count => 10)
end
@@ -80,7 +80,7 @@ def test_generate_message_too_long_with_custom_message
assert_equal 'custom message 10', @person.errors.generate_message(:title, :too_long, :message => 'custom message %{count}', :count => 10)
end
- # validates_length_of: generate_message(attr, :too_short, :default => custom_message, :count => option_value.begin)
+ # validates_length_of: generate_message(attr, :too_short, default: custom_message, count: option_value.begin)
def test_generate_message_too_short_with_default_message
assert_equal "is too short (minimum is 10 characters)", @person.errors.generate_message(:title, :too_short, :count => 10)
end
@@ -89,7 +89,7 @@ def test_generate_message_too_short_with_custom_message
assert_equal 'custom message 10', @person.errors.generate_message(:title, :too_short, :message => 'custom message %{count}', :count => 10)
end
- # validates_length_of: generate_message(attr, :wrong_length, :message => custom_message, :count => option_value)
+ # validates_length_of: generate_message(attr, :wrong_length, message: custom_message, count: option_value)
def test_generate_message_wrong_length_with_default_message
assert_equal "is the wrong length (should be 10 characters)", @person.errors.generate_message(:title, :wrong_length, :count => 10)
end
@@ -98,7 +98,7 @@ def test_generate_message_wrong_length_with_custom_message
assert_equal 'custom message 10', @person.errors.generate_message(:title, :wrong_length, :message => 'custom message %{count}', :count => 10)
end
- # validates_numericality_of: generate_message(attr_name, :not_a_number, :value => raw_value, :message => custom_message)
+ # validates_numericality_of: generate_message(attr_name, :not_a_number, value: raw_value, message: custom_message)
def test_generate_message_not_a_number_with_default_message
assert_equal "is not a number", @person.errors.generate_message(:title, :not_a_number, :value => 'title')
end
@@ -107,7 +107,7 @@ def test_generate_message_not_a_number_with_custom_message
assert_equal 'custom message title', @person.errors.generate_message(:title, :not_a_number, :message => 'custom message %{value}', :value => 'title')
end
- # validates_numericality_of: generate_message(attr_name, option, :value => raw_value, :default => custom_message)
+ # validates_numericality_of: generate_message(attr_name, option, value: raw_value, default: custom_message)
def test_generate_message_greater_than_with_default_message
assert_equal "must be greater than 10", @person.errors.generate_message(:title, :greater_than, :value => 'title', :count => 10)
end
View
2 activemodel/test/cases/validations/validates_test.rb
@@ -140,7 +140,7 @@ def test_validates_with_included_validator_and_options
end
def test_validates_with_included_validator_and_wildcard_shortcut
- # Shortcut for PersonWithValidator.validates :title, :like => { :with => "Mr." }
+ # Shortcut for PersonWithValidator.validates :title, like: { with: "Mr." }
PersonWithValidator.validates :title, :like => "Mr."
person = PersonWithValidator.new
person.title = "Ms. Pacman"

0 comments on commit 77eb1fb

Please sign in to comment.