Skip to content
This repository
Browse code

Refactor aggregation writer method

Only constantize class_name once.
  • Loading branch information...
commit d5d9a281aaf9bc0fd7f5e92e1609a7677f25887c 1 parent f260dc5
Carlos Antonio da Silva carlosantoniodasilva authored
7 activerecord/lib/active_record/aggregations.rb
@@ -242,10 +242,9 @@ def reader_method(name, class_name, mapping, allow_nil, constructor)
242 242
243 243 def writer_method(name, class_name, mapping, allow_nil, converter)
244 244 define_method("#{name}=") do |part|
245   - unless part.is_a?(class_name.constantize) || converter.nil? || part.nil?
246   - part = converter.respond_to?(:call) ?
247   - converter.call(part) :
248   - class_name.constantize.send(converter, part)
  245 + klass = class_name.constantize
  246 + unless part.is_a?(klass) || converter.nil? || part.nil?
  247 + part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part)
249 248 end
250 249
251 250 if part.nil? && allow_nil
1  activerecord/test/models/customer.rb
... ... @@ -1,5 +1,4 @@
1 1 class Customer < ActiveRecord::Base
2   -
3 2 cattr_accessor :gps_conversion_was_run
4 3
5 4 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.
Something went wrong with that request. Please try again.