method
writer_method
writer_method(name, class_name, mapping, allow_nil, converter)
private
Hide source
# File activerecord/lib/active_record/aggregations.rb, line 236 def writer_method(name, class_name, mapping, allow_nil, converter) define_method("#{name}=") do |part| if part.nil? && allow_nil mapping.each { |pair| self[pair.first] = nil } @aggregation_cache[name] = nil else unless part.is_a?(class_name.constantize) || converter.nil? 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) } @aggregation_cache[name] = part.freeze end end end