diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-12 15:56:07 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-12 15:56:07 -0700 |
commit | 6de1f350ce117129e46353f12f90a138ca3d3ead (patch) | |
tree | 4d25ac9d653ea76a10f682cd0e8e3e7270a569a2 /lib | |
parent | a0dc6900330b7ec78785a80fe8b72595384635a0 (diff) | |
download | rails-6de1f350ce117129e46353f12f90a138ca3d3ead.tar.gz rails-6de1f350ce117129e46353f12f90a138ca3d3ead.tar.bz2 rails-6de1f350ce117129e46353f12f90a138ca3d3ead.zip |
- string passthrough for joins
- blank checks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/primitives/value.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/relations/order.rb | 12 | ||||
-rw-r--r-- | lib/active_relation/relations/relation.rb | 12 | ||||
-rw-r--r-- | lib/active_relation/relations/skip.rb | 5 | ||||
-rw-r--r-- | lib/active_relation/relations/take.rb | 5 |
5 files changed, 22 insertions, 16 deletions
diff --git a/lib/active_relation/primitives/value.rb b/lib/active_relation/primitives/value.rb index 6f251d442b..3fbe907324 100644 --- a/lib/active_relation/primitives/value.rb +++ b/lib/active_relation/primitives/value.rb @@ -23,5 +23,9 @@ module ActiveRelation def qualify self end + + def bind(relation) + Value.new(value, relation) + end end end
\ No newline at end of file diff --git a/lib/active_relation/relations/order.rb b/lib/active_relation/relations/order.rb index 95b73c5e90..d71ff09c41 100644 --- a/lib/active_relation/relations/order.rb +++ b/lib/active_relation/relations/order.rb @@ -1,25 +1,25 @@ module ActiveRelation class Order < Compound - attr_reader :order + attr_reader :ordering def initialize(relation, *orders) - order = orders.pop + ordering = orders.pop @relation = orders.empty?? relation : Order.new(relation, *orders) - @order = order.bind(@relation) + @ordering = ordering.bind(@relation) end def ==(other) self.class == other.class and relation == other.relation and - orders == other.orders + ordering == other.ordering end def descend(&block) - Order.new(relation.descend(&block), *orders.collect(&block)) + Order.new(relation.descend(&block), yield(ordering)) end def orders - relation.orders + [order] + relation.orders + [ordering] end end end
\ No newline at end of file diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index 29c6fbbed0..f5f2809724 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -41,27 +41,27 @@ module ActiveRelation end def select(*predicates) - Selection.new(self, *predicates) + predicates.all?(&:blank?) ? self : Selection.new(self, *predicates) end def project(*attributes) - Projection.new(self, *attributes) + attributes.all?(&:blank?) ? self : Projection.new(self, *attributes) end def as(aliaz) - Alias.new(self, aliaz) + aliaz.blank?? self : Alias.new(self, aliaz) end def order(*attributes) - Order.new(self, *attributes) + attributes.all?(&:blank?) ? self : Order.new(self, *attributes) end def take(taken) - Take.new(self, taken) + taken.blank?? self : Take.new(self, taken) end def skip(skipped) - Skip.new(self, skipped) + skipped.blank?? self : Skip.new(self, skipped) end def rename(attribute, aliaz) diff --git a/lib/active_relation/relations/skip.rb b/lib/active_relation/relations/skip.rb index 7fd5e1603a..3133a3af41 100644 --- a/lib/active_relation/relations/skip.rb +++ b/lib/active_relation/relations/skip.rb @@ -7,8 +7,9 @@ module ActiveRelation end def ==(other) - relation == other.relation and - skipped == other.skipped + self.class == other.class and + relation == other.relation and + skipped == other.skipped end def descend(&block) diff --git a/lib/active_relation/relations/take.rb b/lib/active_relation/relations/take.rb index efeff11bf2..02d507753d 100644 --- a/lib/active_relation/relations/take.rb +++ b/lib/active_relation/relations/take.rb @@ -7,8 +7,9 @@ module ActiveRelation end def ==(other) - relation == other.relation and - taken == other.taken + self.class == other.class and + relation == other.relation and + taken == other.taken end def descend(&block) |