Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Allow making operations on sifters and having them in a group #296

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/squeel/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/squeel/nodes/key_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/squeel/nodes/stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/squeel/visitors/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ def visit_Squeel_Nodes_Operation(o, parent)
op
end

def visit_Squeel_Nodes_Sifter(o, parent)
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
Expand Down