diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-02-16 16:09:37 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-02-16 16:09:37 -0800 |
commit | d5d7a8eb9935cd937441bd5233b410e5a0cfd41b (patch) | |
tree | 6da1391c74af5b6d56f139453d8801754c7147df /lib | |
parent | c910ac7554ad4989c8dd4e942fc14ae78eeddc3d (diff) | |
download | rails-d5d7a8eb9935cd937441bd5233b410e5a0cfd41b.tar.gz rails-d5d7a8eb9935cd937441bd5233b410e5a0cfd41b.tar.bz2 rails-d5d7a8eb9935cd937441bd5233b410e5a0cfd41b.zip |
attribute is now a concrete ancestor of expression. seems logical.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/primitives/attribute.rb | 10 | ||||
-rw-r--r-- | lib/active_relation/primitives/expression.rb | 31 |
2 files changed, 17 insertions, 24 deletions
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb index de25a90868..4a10dffbe5 100644 --- a/lib/active_relation/primitives/attribute.rb +++ b/lib/active_relation/primitives/attribute.rb @@ -34,11 +34,11 @@ module ActiveRelation end def ==(other) - self.class == other.class and - relation == other.relation and - name == other.name and - @alias == other.alias and - ancestor == other.ancestor + self.class == other.class and + relation == other.relation and + name == other.name and + @alias == other.alias and + ancestor == other.ancestor end alias_method :eql?, :== diff --git a/lib/active_relation/primitives/expression.rb b/lib/active_relation/primitives/expression.rb index 6ff06c7f81..4d28ef108c 100644 --- a/lib/active_relation/primitives/expression.rb +++ b/lib/active_relation/primitives/expression.rb @@ -1,23 +1,24 @@ module ActiveRelation - class Expression + class Expression < Attribute include Sql::Quoting - attr_reader :attribute, :function_sql, :alias, :ancestor + attr_reader :attribute, :function_sql delegate :relation, :to => :attribute + alias_method :name, :alias def initialize(attribute, function_sql, aliaz = nil, ancestor = nil) @attribute, @function_sql, @alias, @ancestor = attribute, function_sql, aliaz, ancestor end module Transformations - def bind(new_relation) - new_relation == relation ? self : Expression.new(attribute.bind(new_relation), function_sql, @alias, self) - end - def as(aliaz) Expression.new(attribute, function_sql, aliaz, self) end + def bind(new_relation) + new_relation == relation ? self : Expression.new(attribute.bind(new_relation), function_sql, @alias, self) + end + def to_attribute Attribute.new(relation, @alias, nil, self) end @@ -29,20 +30,12 @@ module ActiveRelation end def ==(other) - self.class == other.class and attribute == other.attribute and function_sql == other.function_sql and ancestor == other.ancestor and @alias == other.alias + self.class == other.class and + attribute == other.attribute and + function_sql == other.function_sql and + ancestor == other.ancestor and + @alias == other.alias end alias_method :eql?, :== - - def =~(other) - !(history & other.send(:history)).empty? - end - - def hash - attribute.hash + function_sql.hash - end - - def history - [self] + (ancestor ? [ancestor, ancestor.send(:history)].flatten : []) - end end end
\ No newline at end of file |