aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r--lib/arel/algebra/predicates.rb28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/arel/algebra/predicates.rb b/lib/arel/algebra/predicates.rb
index 1b9667ac13..b761eab417 100644
--- a/lib/arel/algebra/predicates.rb
+++ b/lib/arel/algebra/predicates.rb
@@ -1,6 +1,6 @@
module Arel
module Predicates
- class Predicate < Struct.new(:children)
+ class Predicate
def or(other_predicate)
Or.new(self, other_predicate)
end
@@ -16,17 +16,13 @@ module Arel
def not
self.complement
end
-
- def == other
- super || (self.class === other && children == other.children)
- end
end
class Polyadic < Predicate
- alias :predicates :children
+ attr_reader :predicates
def initialize(*predicates)
- super(predicates)
+ @predicates = predicates
end
# Build a Polyadic predicate based on:
@@ -42,6 +38,10 @@ module Arel
)
end
+ def ==(other)
+ super || predicates == other.predicates
+ end
+
def bind(relation)
self.class.new(
*predicates.map {|p| p.find_correlate_in(relation)}
@@ -62,11 +62,19 @@ module Arel
end
class Unary < Predicate
- alias :operand :children
+ attr_reader :operand
+
+ def initialize operand
+ @operand = operand
+ end
def bind(relation)
self.class.new(operand.find_correlate_in(relation))
end
+
+ def == other
+ super || self.class === other && operand == other.operand
+ end
end
class Not < Unary
@@ -75,9 +83,9 @@ module Arel
end
end
- class Binary < Predicate
- alias :operand1 :children
+ class Binary < Unary
attr_reader :operand2
+ alias :operand1 :operand
def initialize left, right
super(left)