diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2008-05-27 21:56:38 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2008-05-27 21:56:38 -0400 |
commit | aeb09afd73cf188c6aee22bf4dd0f1beb937ac22 (patch) | |
tree | 051780a6e22ca2e0d61e9361abc8037ae8e492c3 /lib | |
parent | 191b2b7b7e6e2cf4fc5a24321bc9b1e593f96551 (diff) | |
download | rails-aeb09afd73cf188c6aee22bf4dd0f1beb937ac22.tar.gz rails-aeb09afd73cf188c6aee22bf4dd0f1beb937ac22.tar.bz2 rails-aeb09afd73cf188c6aee22bf4dd0f1beb937ac22.zip |
AND/OR support for predicates
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) |