From 2a91d807538a4d39c5755fb83a5e9462e8056fa6 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Mon, 18 Feb 2008 15:08:03 -0800 Subject: made descend public; added test coverage for it; tests for qualify are now in terms of descend --- lib/active_relation/predicates.rb | 1 - lib/active_relation/relations/aggregation.rb | 1 - lib/active_relation/relations/join.rb | 8 ++++---- lib/active_relation/relations/order.rb | 1 - lib/active_relation/relations/projection.rb | 1 - lib/active_relation/relations/range.rb | 1 - lib/active_relation/relations/relation.rb | 1 - lib/active_relation/relations/rename.rb | 1 - lib/active_relation/relations/selection.rb | 9 ++++----- 9 files changed, 8 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb index 67d910b9d1..c4f7b83512 100644 --- a/lib/active_relation/predicates.rb +++ b/lib/active_relation/predicates.rb @@ -28,7 +28,6 @@ module ActiveRelation "#{attribute.to_sql(strategy)} #{predicate_sql} #{operand.to_sql(strategy)}" end - protected def descend self.class.new(yield(attribute), yield(operand)) end diff --git a/lib/active_relation/relations/aggregation.rb b/lib/active_relation/relations/aggregation.rb index de21d2f383..d3a026820d 100644 --- a/lib/active_relation/relations/aggregation.rb +++ b/lib/active_relation/relations/aggregation.rb @@ -21,7 +21,6 @@ module ActiveRelation true end - protected def descend(&block) Aggregation.new(relation.descend(&block), :expressions => expressions.collect(&block), :groupings => groupings.collect(&block)) end diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb index 6185293c8a..850a773ee5 100644 --- a/lib/active_relation/relations/join.rb +++ b/lib/active_relation/relations/join.rb @@ -31,6 +31,10 @@ module ActiveRelation end alias_method :aliased_prefix_for, :prefix_for + def descend(&block) + Join.new(join_sql, relation1.descend(&block), relation2.descend(&block), *predicates.collect(&block)) + end + protected def joins right_table_sql = relation2.aggregation?? relation2.to_sql(Sql::Aggregation.new) : relation2.send(:table_sql) @@ -48,9 +52,5 @@ module ActiveRelation def table_sql relation1.aggregation?? relation1.to_sql(Sql::Aggregation.new) : relation1.send(:table_sql) end - - def descend(&block) - Join.new(join_sql, relation1.descend(&block), relation2.descend(&block), *predicates.collect(&block)) - 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 cee6278c80..e6395aecd7 100644 --- a/lib/active_relation/relations/order.rb +++ b/lib/active_relation/relations/order.rb @@ -11,7 +11,6 @@ module ActiveRelation orders == other.orders end - protected def descend(&block) Order.new(relation.descend(&block), *orders.collect(&block)) end diff --git a/lib/active_relation/relations/projection.rb b/lib/active_relation/relations/projection.rb index cd08a5aa54..c478ae145f 100644 --- a/lib/active_relation/relations/projection.rb +++ b/lib/active_relation/relations/projection.rb @@ -16,7 +16,6 @@ module ActiveRelation projections == other.projections end - protected def descend(&block) Projection.new(relation.descend(&block), *projections.collect(&block)) end diff --git a/lib/active_relation/relations/range.rb b/lib/active_relation/relations/range.rb index 14a86b8c65..fafdef5902 100644 --- a/lib/active_relation/relations/range.rb +++ b/lib/active_relation/relations/range.rb @@ -19,7 +19,6 @@ module ActiveRelation range.begin end - protected def descend(&block) Range.new(relation.descend(&block), range) end diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index 7d33b42faf..e0ae882475 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -103,7 +103,6 @@ module ActiveRelation end alias_method :to_s, :to_sql - protected def descend yield self end diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb index 1705d9ba8c..9a0e5552c7 100644 --- a/lib/active_relation/relations/rename.rb +++ b/lib/active_relation/relations/rename.rb @@ -18,7 +18,6 @@ module ActiveRelation relation.attributes.collect(&method(:baptize)) end - protected def descend(&block) Rename.new(relation.descend(&block), yield(attribute) => pseudonym) end diff --git a/lib/active_relation/relations/selection.rb b/lib/active_relation/relations/selection.rb index f8cd235419..e7a91f7572 100644 --- a/lib/active_relation/relations/selection.rb +++ b/lib/active_relation/relations/selection.rb @@ -13,14 +13,13 @@ module ActiveRelation predicate == other.predicate end - protected - def selects - relation.send(:selects) + [predicate] - end - def descend(&block) Selection.new(relation.descend(&block), yield(predicate)) end + protected + def selects + relation.send(:selects) + [predicate] + end end end \ No newline at end of file -- cgit v1.2.3