aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-20 15:43:34 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-20 15:43:34 -0700
commit2f32aa068513c6bd1fab63087756417e01af06c8 (patch)
tree6612d7f3ce2e5bc65595e8c4275ff0af237a27f0 /lib/arel
parent86dd717c203f6056b4fa367080c989c3411b7300 (diff)
downloadrails-2f32aa068513c6bd1fab63087756417e01af06c8.tar.gz
rails-2f32aa068513c6bd1fab63087756417e01af06c8.tar.bz2
rails-2f32aa068513c6bd1fab63087756417e01af06c8.zip
use OO instead of meta programming
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/algebra/predicates.rb26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/arel/algebra/predicates.rb b/lib/arel/algebra/predicates.rb
index 88e0ae9b18..b60d976b4e 100644
--- a/lib/arel/algebra/predicates.rb
+++ b/lib/arel/algebra/predicates.rb
@@ -1,6 +1,6 @@
module Arel
module Predicates
- class Predicate
+ class Predicate < Struct.new(:children)
def or(other_predicate)
Or.new(self, other_predicate)
end
@@ -16,13 +16,17 @@ module Arel
def not
self.complement
end
+
+ def == other
+ super || (self.class === other && children == other.children)
+ end
end
class Polyadic < Predicate
- attr_reader :predicates
+ alias :predicates :children
def initialize(*predicates)
- @predicates = predicates
+ super(predicates)
end
# Build a Polyadic predicate based on:
@@ -72,8 +76,7 @@ module Arel
end
class Unary < Predicate
- attributes :operand
- deriving :initialize, :==
+ alias :operand :children
def bind(relation)
self.class.new(operand.find_correlate_in(relation))
@@ -87,13 +90,16 @@ module Arel
end
class Binary < Predicate
- attributes :operand1, :operand2
- deriving :initialize
+ alias :operand1 :children
+ attr_reader :operand2
+
+ def initialize left, right
+ super(left)
+ @operand2 = right
+ end
def ==(other)
- self.class === other and
- @operand1 == other.operand1 and
- @operand2 == other.operand2
+ super && @operand2 == other.operand2
end
def bind(relation)