Skip to content

Commit

Permalink
send() will raise an ArgumentError, so we should leverage ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 7, 2011
1 parent 6e63e7a commit 2efd780
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
22 changes: 6 additions & 16 deletions activerecord/lib/active_record/aggregations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,9 @@ def reader_method(name, class_name, mapping, allow_nil, constructor)
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]
Expand All @@ -248,14 +243,9 @@ def writer_method(name, class_name, mapping, allow_nil, converter)
@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) }
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def initialize(first, last = nil)
def to_s
"#{first} #{last.upcase}"
end
end
end

0 comments on commit 2efd780

Please sign in to comment.