aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/where.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra/relations/operations/where.rb')
-rw-r--r--lib/arel/algebra/relations/operations/where.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/arel/algebra/relations/operations/where.rb b/lib/arel/algebra/relations/operations/where.rb
new file mode 100644
index 0000000000..608aaeb4b7
--- /dev/null
+++ b/lib/arel/algebra/relations/operations/where.rb
@@ -0,0 +1,16 @@
+module Arel
+ class Where < Compound
+ attributes :relation, :predicate
+ deriving :==
+
+ def initialize(relation, *predicates, &block)
+ predicate = block_given?? yield(relation) : predicates.shift
+ @relation = predicates.empty?? relation : Where.new(relation, *predicates)
+ @predicate = predicate.bind(@relation)
+ end
+
+ def wheres
+ @wheres ||= (relation.wheres + [predicate]).collect { |p| p.bind(self) }
+ end
+ end
+end