aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-05-21 18:34:31 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-05-21 18:34:58 -0300
commitd5d9a281aaf9bc0fd7f5e92e1609a7677f25887c (patch)
tree360154517867e00d77360368892e6c4cf51c5b11 /activerecord
parentf260dc53be27448d9052098369d31d8ecd626839 (diff)
downloadrails-d5d9a281aaf9bc0fd7f5e92e1609a7677f25887c.tar.gz
rails-d5d9a281aaf9bc0fd7f5e92e1609a7677f25887c.tar.bz2
rails-d5d9a281aaf9bc0fd7f5e92e1609a7677f25887c.zip
Refactor aggregation writer method
Only constantize class_name once.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/aggregations.rb7
-rw-r--r--activerecord/test/models/customer.rb1
2 files changed, 3 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index 5de10a8dd6..f0b549e5ad 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -242,10 +242,9 @@ module ActiveRecord
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
diff --git a/activerecord/test/models/customer.rb b/activerecord/test/models/customer.rb
index 807f25b687..7e8e82542f 100644
--- a/activerecord/test/models/customer.rb
+++ b/activerecord/test/models/customer.rb
@@ -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