aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-06-25 14:24:46 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-06-26 22:21:18 -0300
commit0ee6aa749cde21dad0e5f394a7feb3173f357d2f (patch)
tree81105a9a27084b1a759a65f98e0d1766a89d4cd6 /activemodel/lib
parent60571b853920707c1103c5f9659e7b690d8eae73 (diff)
downloadrails-0ee6aa749cde21dad0e5f394a7feb3173f357d2f.tar.gz
rails-0ee6aa749cde21dad0e5f394a7feb3173f357d2f.tar.bz2
rails-0ee6aa749cde21dad0e5f394a7feb3173f357d2f.zip
Set hash value instead of merge a single key, and use flatten! if possible
There's no need to create two extra hashes with options.merge(another_hash), with the goal of setting only one value, so lets just set it. Also refactor validates_each to use _merge_attributes, like other validates_* helpers do.
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/validations.rb3
-rw-r--r--activemodel/lib/active_model/validations/with.rb6
2 files changed, 5 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index cd596e37d2..55ea6be796 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -82,8 +82,7 @@ module ActiveModel
# <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
def validates_each(*attr_names, &block)
- options = attr_names.extract_options!.symbolize_keys
- validates_with BlockValidator, options.merge(:attributes => attr_names.flatten), &block
+ validates_with BlockValidator, _merge_attributes(attr_names), &block
end
# Adds a validation method or block to the class. This is useful when
diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb
index 3158f36b6e..3c516f8b22 100644
--- a/activemodel/lib/active_model/validations/with.rb
+++ b/activemodel/lib/active_model/validations/with.rb
@@ -3,8 +3,10 @@ module ActiveModel
module HelperMethods
private
def _merge_attributes(attr_names)
- options = attr_names.extract_options!
- options.merge(:attributes => attr_names.flatten)
+ options = attr_names.extract_options!.symbolize_keys
+ attr_names.flatten!
+ options[:attributes] = attr_names
+ options
end
end