From aeb09afd73cf188c6aee22bf4dd0f1beb937ac22 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 27 May 2008 21:56:38 -0400 Subject: AND/OR support for predicates --- lib/arel/predicates.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') diff --git a/lib/arel/predicates.rb b/lib/arel/predicates.rb index a83bad3c22..051f8abdad 100644 --- a/lib/arel/predicates.rb +++ b/lib/arel/predicates.rb @@ -1,5 +1,12 @@ module Arel class Predicate + def or(other_predicate) + Or.new(self, other_predicate) + end + + def and(other_predicate) + And.new(self, other_predicate) + end end class Binary < Predicate @@ -21,6 +28,20 @@ module Arel end alias_method :to_s, :to_sql end + + class CompoundPredicate < Binary + def to_sql(formatter = nil) + "(#{operand1.to_sql(formatter)} #{predicate_sql} #{operand2.to_sql(formatter)})" + end + end + + class Or < CompoundPredicate + def predicate_sql; "OR" end + end + + class And < CompoundPredicate + def predicate_sql; "AND" end + end class Equality < Binary def ==(other) -- cgit v1.2.3