From c47c3ff918f00e26926fca574614f1bd56c7dcfd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 27 Jul 2010 21:10:23 -0700 Subject: faster method lookup again --- lib/arel/algebra/relations/relation.rb | 51 ++++++++++++++++------------------ 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'lib') diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 9936b9689f..9cb38218c0 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -172,40 +172,37 @@ module Arel end include Operable - module AttributeAccessable - def [](index) - attributes[index] - end + def [](index) + attributes[index] + end - def find_attribute_matching_name(name) - attributes.detect { |a| a.named?(name) } || Attribute.new(self, name) - end + def find_attribute_matching_name(name) + attributes.detect { |a| a.named?(name) } || Attribute.new(self, name) + end - def find_attribute_matching_attribute(attribute) - matching_attributes(attribute).max do |a1, a2| - (a1.original_attribute / attribute) <=> (a2.original_attribute / attribute) - end + def find_attribute_matching_attribute(attribute) + matching_attributes(attribute).max do |a1, a2| + (a1.original_attribute / attribute) <=> (a2.original_attribute / attribute) end + end - def position_of(attribute) - (@position_of ||= Hash.new do |h, attribute| - h[attribute] = attributes.index(self[attribute]) - end)[attribute] - end + def position_of(attribute) + (@position_of ||= Hash.new do |h, attribute| + h[attribute] = attributes.index(self[attribute]) + end)[attribute] + end - private - def matching_attributes(attribute) - (@matching_attributes ||= attributes.inject({}) do |hash, a| - (hash[a.is_a?(Value) ? a.value : a.root] ||= []) << a - hash - end)[attribute.root] || [] - end + private + def matching_attributes(attribute) + (@matching_attributes ||= attributes.inject({}) do |hash, a| + (hash[a.is_a?(Value) ? a.value : a.root] ||= []) << a + hash + end)[attribute.root] || [] + end - def has_attribute?(attribute) - !matching_attributes(attribute).empty? - end + def has_attribute?(attribute) + !matching_attributes(attribute).empty? end - include AttributeAccessable module DefaultOperations def attributes; Header.new end -- cgit v1.2.3