diff options
Diffstat (limited to 'lib/arel/algebra/relations')
-rw-r--r-- | lib/arel/algebra/relations/relation.rb | 51 |
1 files changed, 24 insertions, 27 deletions
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 |