Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor aggregation writer method

Only constantize class_name once.
  • Loading branch information...
commit d5d9a281aaf9bc0fd7f5e92e1609a7677f25887c 1 parent f260dc5
@carlosantoniodasilva carlosantoniodasilva authored
View
7 activerecord/lib/active_record/aggregations.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
View
1  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
Please sign in to comment.
Something went wrong with that request. Please try again.