Permalink
Browse files

Refactor aggregation writer method

Only constantize class_name once.
  • Loading branch information...
carlosantoniodasilva committed May 21, 2012
1 parent f260dc5 commit d5d9a281aaf9bc0fd7f5e92e1609a7677f25887c
Showing with 3 additions and 5 deletions.
  1. +3 −4 activerecord/lib/active_record/aggregations.rb
  2. +0 −1 activerecord/test/models/customer.rb
@@ -242,10 +242,9 @@ def reader_method(name, class_name, mapping, allow_nil, constructor)
def writer_method(name, class_name, mapping, allow_nil, converter)
define_method("#{name}=") do |part|
- unless part.is_a?(class_name.constantize) || converter.nil? || part.nil?
- part = converter.respond_to?(:call) ?
- converter.call(part) :
- class_name.constantize.send(converter, part)
+ klass = class_name.constantize
+ unless part.is_a?(klass) || converter.nil? || part.nil?
+ part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part)
end
if part.nil? && allow_nil
@@ -1,5 +1,4 @@
class Customer < ActiveRecord::Base
-
cattr_accessor :gps_conversion_was_run
composed_of :address, :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ], :allow_nil => true

0 comments on commit d5d9a28

Please sign in to comment.