diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-02-04 20:36:17 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-02-04 20:36:17 -0800 |
commit | 7523c8690deda1b24def03eb049f61baf2f1b466 (patch) | |
tree | cd13473111ff4ced8841a5286ab27b0c2f689457 /lib | |
parent | b6c0de24fadc6b9e124a36aa35718edc027130de (diff) | |
download | rails-7523c8690deda1b24def03eb049f61baf2f1b466.tar.gz rails-7523c8690deda1b24def03eb049f61baf2f1b466.tar.bz2 rails-7523c8690deda1b24def03eb049f61baf2f1b466.zip |
cleaning up code and adding test coverage for attribute and expression.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/primitives/attribute.rb | 19 | ||||
-rw-r--r-- | lib/active_relation/primitives/expression.rb | 13 |
2 files changed, 20 insertions, 12 deletions
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb index c17118f1e8..e6df5cd87c 100644 --- a/lib/active_relation/primitives/attribute.rb +++ b/lib/active_relation/primitives/attribute.rb @@ -30,17 +30,18 @@ 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?, :== def =~(other) - !(history & other.history).empty? + !(history & other.send(:history)).empty? end - def history - [self] + (ancestor ? [ancestor, ancestor.history].flatten : []) - end - module Predications def equals(other) Equality.new(self, other) @@ -96,8 +97,14 @@ module ActiveRelation end private + delegate :hash, :to => :relation + def prefix relation.prefix_for(self) end + + def history + [self] + (ancestor ? [ancestor, ancestor.send(:history)].flatten : []) + end end end
\ No newline at end of file diff --git a/lib/active_relation/primitives/expression.rb b/lib/active_relation/primitives/expression.rb index 47658c49da..a64219e9d1 100644 --- a/lib/active_relation/primitives/expression.rb +++ b/lib/active_relation/primitives/expression.rb @@ -11,7 +11,7 @@ module ActiveRelation module Transformations def substitute(new_relation) - Expression.new(attribute.substitute(new_relation), function_sql, @alias, self) + new_relation == relation ? self : Expression.new(attribute.substitute(new_relation), function_sql, @alias, self) end def as(aliaz) @@ -34,17 +34,18 @@ module ActiveRelation 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 + private def hash attribute.hash + function_sql.hash end - def =~(other) - !(history & other.history).empty? - end - def history - [self] + (ancestor ? [ancestor, ancestor.history].flatten : []) + [self] + (ancestor ? [ancestor, ancestor.send(:history)].flatten : []) end end end
\ No newline at end of file |