diff options
Diffstat (limited to 'lib/arel/engines/memory/predicates.rb')
-rw-r--r-- | lib/arel/engines/memory/predicates.rb | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/lib/arel/engines/memory/predicates.rb b/lib/arel/engines/memory/predicates.rb index d0963e2f74..c0ee862626 100644 --- a/lib/arel/engines/memory/predicates.rb +++ b/lib/arel/engines/memory/predicates.rb @@ -5,6 +5,49 @@ module Arel operand1.eval(row).send(operator, operand2.eval(row)) end end + + class Unary < Predicate + def eval(row) + operand.eval(row).send(operator) + end + end + + class Not < Unary + def operator; '!' end + end + + class CompoundPredicate < Binary + def eval(row) + eval "operand1.eval(row) #{operator} operand2.eval(row)" + end + end + + class Or < CompoundPredicate + def operator; :or end + end + + class And < CompoundPredicate + def operator; :and end + end + + class GroupedPredicate < Polyadic + def eval(row) + group = additional_operands.inject([]) do |results, operand| + results << operator.new(operand1, operand) + end + group.send(compounder) do |operation| + operation.eval(row) + end + end + end + + class Any < GroupedPredicate + def compounder; :any? end + end + + class All < GroupedPredicate + def compounder; :all? end + end class Equality < Binary def operator; :== end @@ -37,16 +80,20 @@ module Arel end class NotMatch < Binary - def operator; :!~ end + def eval(row) + operand1.eval(row) !~ operand2.eval(row) + end end class In < Binary - def operator; :include? end + def eval(row) + operand2.eval(row).include?(operand1.eval(row)) + end end class NotIn < Binary def eval(row) - !(operand1.eval(row).include?(operand2.eval(row))) + !(operand2.eval(row).include?(operand1.eval(row))) end end end |