diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-28 13:55:22 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-28 14:55:00 -0700 |
commit | afcfe97517f6c0c872c0eb79fc505cf85b1a3e74 (patch) | |
tree | 99eada88a1257146aefff7e2f25ce678f4f2441d | |
parent | a0425099d78c1884478ee3e69a09ea5f7afa1aa9 (diff) | |
download | rails-afcfe97517f6c0c872c0eb79fc505cf85b1a3e74.tar.gz rails-afcfe97517f6c0c872c0eb79fc505cf85b1a3e74.tar.bz2 rails-afcfe97517f6c0c872c0eb79fc505cf85b1a3e74.zip |
speed up method lookup and reduce API footprint
-rw-r--r-- | lib/arel/algebra/attributes/attribute.rb | 25 | ||||
-rw-r--r-- | spec/algebra/unit/primitives/attribute_spec.rb | 2 |
2 files changed, 12 insertions, 15 deletions
diff --git a/lib/arel/algebra/attributes/attribute.rb b/lib/arel/algebra/attributes/attribute.rb index 90a3b13938..50d79fa4b9 100644 --- a/lib/arel/algebra/attributes/attribute.rb +++ b/lib/arel/algebra/attributes/attribute.rb @@ -43,24 +43,21 @@ module Arel alias :eql? :== - module Transformations - def hash - @hash ||= name.hash + root.relation.hash - end + def hash + @hash ||= name.hash + root.relation.hash + end - def as(aliaz = nil) - Attribute.new(relation, name, :alias => aliaz, :ancestor => self) - end + def as(aliaz = nil) + Attribute.new(relation, name, :alias => aliaz, :ancestor => self) + end - def bind(new_relation) - relation == new_relation ? self : Attribute.new(new_relation, name, :alias => @alias, :ancestor => self) - end + def bind(new_relation) + relation == new_relation ? self : Attribute.new(new_relation, name, :alias => @alias, :ancestor => self) + end - def to_attribute(relation) - bind(relation) - end + def to_attribute(relation) + bind(relation) end - include Transformations module Congruence def history diff --git a/spec/algebra/unit/primitives/attribute_spec.rb b/spec/algebra/unit/primitives/attribute_spec.rb index d030e60a4c..08d32614a1 100644 --- a/spec/algebra/unit/primitives/attribute_spec.rb +++ b/spec/algebra/unit/primitives/attribute_spec.rb @@ -7,7 +7,7 @@ module Arel @attribute = @relation[:id] end - describe Attribute::Transformations do + describe 'Attribute::Transformations' do describe '#as' do it "manufactures an aliased attributed" do @attribute.as(:alias).should == Attribute.new(@relation, @attribute.name, :alias => :alias, :ancestor => @attribute) |