Permalink
Browse files

Sifters must be prefixed with sifter.

This is to eliminate confusion between sifters and scopes. They aren't
the same thing. Related to #142. Still on the fence about having the
sifter macro define a scope to match, but I'm leaning toward it being
too much unnecessary magic for now.
  • Loading branch information...
1 parent c2bbcfb commit bbbce192e0df1bdac5c8d7055d8d9515af8b573f @ernie ernie committed Mar 24, 2013
@@ -9,7 +9,7 @@ def squeel(&block)
def sifter(name = nil)
if Symbol === name && block_given?
- singleton_class.send :define_method, name,
+ singleton_class.send :define_method, "sifter_#{name}",
lambda {|*args| DSL.exec(*args, &Proc.new)}
else
raise ArgumentError, "A name and block are required"
@@ -16,7 +16,7 @@ module PredicateVisitation
# @return The result of visiting the executed block's return value
def visit_Squeel_Nodes_Sifter(o, parent)
klass = classify(parent)
- visit(klass.send(o.name, *o.args), parent)
+ visit(klass.send("sifter_#{o.name}", *o.args), parent)
end
# Visit a Squeel predicate, converting it into an ARel predicate
@@ -22,24 +22,24 @@ module ActiveRecord
end
end
- it { should respond_to :title_or_body_contains }
- specify { subject.title_or_body_contains('ernie').should be_a Nodes::Or }
+ it { should respond_to :sifter_title_or_body_contains }
+ specify { subject.sifter_title_or_body_contains('ernie').should be_a Nodes::Or }
end
context 'with a sifter defined via method' do
before :all do
- def subject.title_starts_with(val)
+ def subject.sifter_title_starts_with(val)
squeel{title =~ "#{val}%"}
end
end
- it { should respond_to :title_starts_with }
- specify { subject.title_starts_with('ernie').should be_a Nodes::Predicate }
+ it { should respond_to :sifter_title_starts_with }
+ specify { subject.sifter_title_starts_with('ernie').should be_a Nodes::Predicate }
end
end
end
end
end
-end
+end

1 comment on commit bbbce19

Please sign in to comment.