From 4bd9482a1a890c50264b4a9320e6853f1a0bde69 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 3 May 2012 00:47:50 +0100 Subject: de-globalise method --- activerecord/lib/active_record/dynamic_matchers.rb | 9 +-------- activerecord/lib/active_record/reflection.rb | 4 ++++ activerecord/lib/active_record/sanitization.rb | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb index f3f143940f..96a3a69d0d 100644 --- a/activerecord/lib/active_record/dynamic_matchers.rb +++ b/activerecord/lib/active_record/dynamic_matchers.rb @@ -63,9 +63,7 @@ module ActiveRecord def expand_attribute_names_for_aggregates attribute_names.map do |attribute_name| if aggregation = model.reflect_on_aggregation(attribute_name.to_sym) - model.send(:aggregate_mapping, aggregation).map do |field_attr, _| - field_attr.to_sym - end + aggregation.mapping.map { |m| m.first.to_sym } else attribute_name.to_sym end @@ -240,10 +238,5 @@ module ActiveRecord "create!" end end - - def aggregate_mapping(reflection) - mapping = reflection.options[:mapping] || [reflection.name, reflection.name] - mapping.first.is_a?(Array) ? mapping : [mapping] - end end end diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index d4f4d593c6..c380b5c029 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -153,6 +153,10 @@ module ActiveRecord # Holds all the meta-data about an aggregation as it was specified in the # Active Record class. class AggregateReflection < MacroReflection #:nodoc: + def mapping + mapping = options[:mapping] || [name, name] + mapping.first.is_a?(Array) ? mapping : [mapping] + end end # Holds all the meta-data about an association as it was specified in the diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb index 81b13fe529..5530be3219 100644 --- a/activerecord/lib/active_record/sanitization.rb +++ b/activerecord/lib/active_record/sanitization.rb @@ -58,7 +58,7 @@ module ActiveRecord expanded_attrs = {} attrs.each do |attr, value| if aggregation = reflect_on_aggregation(attr.to_sym) - mapping = aggregate_mapping(aggregation) + mapping = aggregation.mapping mapping.each do |field_attr, aggregate_attr| if mapping.size == 1 && !value.respond_to?(aggregate_attr) expanded_attrs[field_attr] = value -- cgit v1.2.3