Skip to content

Commit

Permalink
Set hash value instead of merge a single key, and use flatten! if pos…
Browse files Browse the repository at this point in the history
…sible

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.
  • Loading branch information
carlosantoniodasilva committed Jun 27, 2012
1 parent 60571b8 commit 0ee6aa7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions activemodel/lib/active_model/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ module ClassMethods
# <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
Expand Down
6 changes: 4 additions & 2 deletions activemodel/lib/active_model/validations/with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module Validations
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

Expand Down

0 comments on commit 0ee6aa7

Please sign in to comment.