diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-09-08 08:32:02 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-09-08 09:02:41 -0300 |
commit | 0801f6a3bf6450f9f47635ac642fc2539bd5a73c (patch) | |
tree | 5532aa8a8db2f0257e8d61a56fec12b5aa8f7b65 | |
parent | bf27f6b2f711cc839b023174884c5c3fe3c6dd8d (diff) | |
download | rails-0801f6a3bf6450f9f47635ac642fc2539bd5a73c.tar.gz rails-0801f6a3bf6450f9f47635ac642fc2539bd5a73c.tar.bz2 rails-0801f6a3bf6450f9f47635ac642fc2539bd5a73c.zip |
Refactor nested attributes limit logic to lookup :limit option only once
-rw-r--r-- | activerecord/lib/active_record/nested_attributes.rb | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index f91e41b535..3005dc042c 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -389,17 +389,19 @@ module ActiveRecord raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})" end - limit = case options[:limit] - when Symbol - send(options[:limit]) - when Proc - options[:limit].call - else - options[:limit] - end + if limit = options[:limit] + limit = case limit + when Symbol + send(limit) + when Proc + limit.call + else + limit + end - if limit && attributes_collection.size > limit - raise TooManyRecords, "Maximum #{limit} records are allowed. Got #{attributes_collection.size} records instead." + if limit && attributes_collection.size > limit + raise TooManyRecords, "Maximum #{limit} records are allowed. Got #{attributes_collection.size} records instead." + end end if attributes_collection.is_a? Hash @@ -438,7 +440,6 @@ module ActiveRecord else association.add_to_target(existing_record) end - end if !call_reject_if(association_name, attributes) |