From 0cfc2ae61ce27056c6c3935f0cc901a212617dde Mon Sep 17 00:00:00 2001 From: Oded Niv Date: Mon, 2 Dec 2013 12:13:45 +0200 Subject: [PATCH 1/3] wrap Nodes::Sifter with Nodes::Grouping for operators --- lib/squeel/dsl.rb | 2 +- lib/squeel/nodes/key_path.rb | 2 +- lib/squeel/nodes/stub.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/squeel/dsl.rb b/lib/squeel/dsl.rb index 6b41eea..1137861 100644 --- a/lib/squeel/dsl.rb +++ b/lib/squeel/dsl.rb @@ -86,7 +86,7 @@ def _(expr) # @param [Symbol, Nodes::Stub] name The name of the sifter defined in the model. # @return [Nodes::Sifter] The sifter node def sift(name, *args) - Nodes::Sifter.new name.to_sym, args + Nodes::Grouping.new(Nodes::Sifter.new(name.to_sym, args)) end # Node generation inside DSL blocks. diff --git a/lib/squeel/nodes/key_path.rb b/lib/squeel/nodes/key_path.rb index ea5c813..a543308 100644 --- a/lib/squeel/nodes/key_path.rb +++ b/lib/squeel/nodes/key_path.rb @@ -125,7 +125,7 @@ def op(operator, other) def sift(name, *args) if Stub === endpoint || Join === endpoint @path << Sifter.new(name, args) - self + Grouping.new(self) else no_method_error :sift end diff --git a/lib/squeel/nodes/stub.rb b/lib/squeel/nodes/stub.rb index fd3f38c..d2fa470 100644 --- a/lib/squeel/nodes/stub.rb +++ b/lib/squeel/nodes/stub.rb @@ -108,7 +108,7 @@ def inner # Create a keypath with a sifter as its endpoint # @return [KeyPath] The new KeyPath def sift(name, *args) - KeyPath.new([self, Sifter.new(name, args)]) + Grouping.new(KeyPath.new([self, Sifter.new(name, args)])) end # Create an outer Join node for the association named by this Stub From 5c1eec386e3a2c9d7b53f8b078baa94918af9aaf Mon Sep 17 00:00:00 2001 From: Oded Niv Date: Mon, 2 Dec 2013 15:15:36 +0200 Subject: [PATCH 2/3] allow sifter visitation --- lib/squeel/visitors/visitor.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/squeel/visitors/visitor.rb b/lib/squeel/visitors/visitor.rb index e44cdf4..36eaffd 100644 --- a/lib/squeel/visitors/visitor.rb +++ b/lib/squeel/visitors/visitor.rb @@ -362,6 +362,10 @@ def visit_Squeel_Nodes_Operation(o, parent) op end + def visit_Squeel_Nodes_Sifter(o, parent) + Arel::Nodes::Grouping.new(visit(context.base.active_record.send("sifter_#{o.name}", *o.args), parent)) + end + # Visit an Active Record Relation, returning an Arel::SelectManager # @param [ActiveRecord::Relation] o The Relation to visit # @param parent The parent object in the context From 8f227d5e31cea5fb706b9ca1a979dfdc3c194681 Mon Sep 17 00:00:00 2001 From: Oded Niv Date: Mon, 2 Dec 2013 15:27:48 +0200 Subject: [PATCH 3/3] remove unnecessary Grouping when visiting Sifter --- lib/squeel/visitors/visitor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/squeel/visitors/visitor.rb b/lib/squeel/visitors/visitor.rb index 36eaffd..f7cdb3a 100644 --- a/lib/squeel/visitors/visitor.rb +++ b/lib/squeel/visitors/visitor.rb @@ -363,7 +363,7 @@ def visit_Squeel_Nodes_Operation(o, parent) end def visit_Squeel_Nodes_Sifter(o, parent) - Arel::Nodes::Grouping.new(visit(context.base.active_record.send("sifter_#{o.name}", *o.args), parent)) + visit(context.base.active_record.send("sifter_#{o.name}", *o.args), parent) end # Visit an Active Record Relation, returning an Arel::SelectManager