diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/predicates.rb | 21 |
1 files changed, 21 insertions, 0 deletions
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) |