diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-07 14:30:20 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-07 14:30:20 -0800 |
commit | 2efd780dcb91b9df5eb05ae8b4837602a33c16fc (patch) | |
tree | 4c7946c1dbd9bffcdda7fc665fb6282859d5e3da /activerecord | |
parent | 6e63e7a8745083e2a2556df268589f8bd9e7cd31 (diff) | |
download | rails-2efd780dcb91b9df5eb05ae8b4837602a33c16fc.tar.gz rails-2efd780dcb91b9df5eb05ae8b4837602a33c16fc.tar.bz2 rails-2efd780dcb91b9df5eb05ae8b4837602a33c16fc.zip |
send() will raise an ArgumentError, so we should leverage ruby
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/aggregations.rb | 22 | ||||
-rw-r--r-- | activerecord/test/models/customer.rb | 2 |
2 files changed, 7 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index 44e595383e..0bc26cc672 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -224,14 +224,9 @@ module ActiveRecord define_method(name) do if @aggregation_cache[name].nil? && (!allow_nil || mapping.any? {|pair| !read_attribute(pair.first).nil? }) attrs = mapping.collect {|pair| read_attribute(pair.first)} - object = case constructor - when Symbol - class_name.constantize.send(constructor, *attrs) - when Proc, Method - constructor.call(*attrs) - else - raise ArgumentError, 'Constructor must be a symbol denoting the constructor method to call or a Proc to be invoked.' - end + object = constructor.respond_to?(:call) ? + constructor.call(*attrs) : + class_name.constantize.send(constructor, *attrs) @aggregation_cache[name] = object end @aggregation_cache[name] @@ -248,14 +243,9 @@ module ActiveRecord @aggregation_cache[name] = nil else unless part.is_a?(class_name.constantize) || converter.nil? - part = case converter - when Symbol - class_name.constantize.send(converter, part) - when Proc, Method - converter.call(part) - else - raise ArgumentError, 'Converter must be a symbol denoting the converter method to call or a Proc to be invoked.' - end + part = converter.respond_to?(:call) ? + converter.call(part) : + class_name.constantize.send(converter, part) end mapping.each { |pair| self[pair.first] = part.send(pair.last) } diff --git a/activerecord/test/models/customer.rb b/activerecord/test/models/customer.rb index e258ccdb6c..777f6b5ba0 100644 --- a/activerecord/test/models/customer.rb +++ b/activerecord/test/models/customer.rb @@ -70,4 +70,4 @@ class Fullname def to_s "#{first} #{last.upcase}" end -end
\ No newline at end of file +end |