aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-27 21:10:23 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-27 21:10:23 -0700
commitc47c3ff918f00e26926fca574614f1bd56c7dcfd (patch)
treea4efe556608d43f3db30de9d557619360e6d6311 /lib
parent288eb6d7ba4fd1f2a27357f8ec889496e9b8542c (diff)
downloadrails-c47c3ff918f00e26926fca574614f1bd56c7dcfd.tar.gz
rails-c47c3ff918f00e26926fca574614f1bd56c7dcfd.tar.bz2
rails-c47c3ff918f00e26926fca574614f1bd56c7dcfd.zip
faster method lookup again
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/algebra/relations/relation.rb51
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