From 6de1f350ce117129e46353f12f90a138ca3d3ead Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sat, 12 Apr 2008 15:56:07 -0700 Subject: - string passthrough for joins - blank checks --- lib/active_relation/primitives/value.rb | 4 ++++ lib/active_relation/relations/order.rb | 12 ++++++------ lib/active_relation/relations/relation.rb | 12 ++++++------ lib/active_relation/relations/skip.rb | 5 +++-- lib/active_relation/relations/take.rb | 5 +++-- 5 files changed, 22 insertions(+), 16 deletions(-) (limited to 'lib') 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) -- cgit v1.2.3