aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-26 10:52:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-26 10:52:21 -0700
commit2598ee0f61ecb40b1c746d339c6853d1835992f8 (patch)
tree46ff4f817b14d95a70a268f6f8353300ce3aaf7e /lib
parentef231deb9ef032e0910dcaec240b70996fc5e44e (diff)
downloadrails-2598ee0f61ecb40b1c746d339c6853d1835992f8.tar.gz
rails-2598ee0f61ecb40b1c746d339c6853d1835992f8.tar.bz2
rails-2598ee0f61ecb40b1c746d339c6853d1835992f8.zip
removing unhelpful organization
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/algebra/predicates.rb59
-rw-r--r--lib/arel/engines/memory.rb1
-rw-r--r--lib/arel/engines/memory/predicates.rb99
3 files changed, 58 insertions, 101 deletions
diff --git a/lib/arel/algebra/predicates.rb b/lib/arel/algebra/predicates.rb
index b761eab417..5b65b59c8c 100644
--- a/lib/arel/algebra/predicates.rb
+++ b/lib/arel/algebra/predicates.rb
@@ -47,18 +47,28 @@ module Arel
*predicates.map {|p| p.find_correlate_in(relation)}
)
end
+
+ def eval(row)
+ predicates.send(compounder) do |operation|
+ operation.eval(row)
+ end
+ end
end
class Any < Polyadic
def complement
All.new(*predicates.map {|p| p.complement})
end
+
+ def compounder; :any? end
end
class All < Polyadic
def complement
Any.new(*predicates.map {|p| p.complement})
end
+
+ def compounder; :all? end
end
class Unary < Predicate
@@ -75,12 +85,20 @@ module Arel
def == other
super || self.class === other && operand == other.operand
end
+
+ def eval(row)
+ operand.eval(row).send(operator)
+ end
end
class Not < Unary
def complement
operand
end
+
+ def eval(row)
+ !operand.eval(row)
+ end
end
class Binary < Unary
@@ -99,20 +117,31 @@ module Arel
def bind(relation)
self.class.new(operand1.find_correlate_in(relation), operand2.find_correlate_in(relation))
end
+
+ def eval(row)
+ operand1.eval(row).send(operator, operand2.eval(row))
+ end
end
- class CompoundPredicate < Binary; end
+ class CompoundPredicate < Binary
+ def eval(row)
+ eval "operand1.eval(row) #{operator} operand2.eval(row)"
+ end
+ end
class And < CompoundPredicate
def complement
Or.new(operand1.complement, operand2.complement)
end
+
+ def operator; :and end
end
class Or < CompoundPredicate
def complement
And.new(operand1.complement, operand2.complement)
end
+ def operator; :or end
end
class Equality < Binary
@@ -125,60 +154,88 @@ module Arel
def complement
Inequality.new(operand1, operand2)
end
+
+ def operator; :== end
end
class Inequality < Equality
def complement
Equality.new(operand1, operand2)
end
+
+ def eval(row)
+ operand1.eval(row) != operand2.eval(row)
+ end
end
class GreaterThanOrEqualTo < Binary
def complement
LessThan.new(operand1, operand2)
end
+
+ def operator; :>= end
end
class GreaterThan < Binary
def complement
LessThanOrEqualTo.new(operand1, operand2)
end
+
+ def operator; :> end
end
class LessThanOrEqualTo < Binary
def complement
GreaterThan.new(operand1, operand2)
end
+
+ def operator; :<= end
end
class LessThan < Binary
def complement
GreaterThanOrEqualTo.new(operand1, operand2)
end
+
+ def operator; :< end
end
class Match < Binary
def complement
NotMatch.new(operand1, operand2)
end
+
+ def operator; :=~ end
end
class NotMatch < Binary
def complement
Match.new(operand1, operand2)
end
+
+ def eval(row)
+ operand1.eval(row) !~ operand2.eval(row)
+ end
end
class In < Binary
def complement
NotIn.new(operand1, operand2)
end
+
+ def eval(row)
+ operand2.eval(row).include?(operand1.eval(row))
+ end
end
class NotIn < Binary
def complement
In.new(operand1, operand2)
end
+
+ def eval(row)
+ !(operand2.eval(row).include?(operand1.eval(row)))
+ end
end
end
end
diff --git a/lib/arel/engines/memory.rb b/lib/arel/engines/memory.rb
index 9e7193ef13..5a963e8ba1 100644
--- a/lib/arel/engines/memory.rb
+++ b/lib/arel/engines/memory.rb
@@ -1,4 +1,3 @@
require 'arel/engines/memory/relations'
require 'arel/engines/memory/primitives'
require 'arel/engines/memory/engine'
-require 'arel/engines/memory/predicates'
diff --git a/lib/arel/engines/memory/predicates.rb b/lib/arel/engines/memory/predicates.rb
deleted file mode 100644
index 1527b04056..0000000000
--- a/lib/arel/engines/memory/predicates.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-module Arel
- module Predicates
- class Binary < Unary
- def eval(row)
- operand1.eval(row).send(operator, operand2.eval(row))
- end
- end
-
- class Unary < Predicate
- def eval(row)
- operand.eval(row).send(operator)
- end
- end
-
- class Not < Unary
- def eval(row)
- !operand.eval(row)
- end
- end
-
- class Polyadic < Predicate
- def eval(row)
- predicates.send(compounder) do |operation|
- operation.eval(row)
- end
- end
- end
-
- class Any < Polyadic
- def compounder; :any? end
- end
-
- class All < Polyadic
- def compounder; :all? end
- end
-
- class CompoundPredicate < Binary
- def eval(row)
- eval "operand1.eval(row) #{operator} operand2.eval(row)"
- end
- end
-
- class Or < CompoundPredicate
- def operator; :or end
- end
-
- class And < CompoundPredicate
- def operator; :and end
- end
-
- class Equality < Binary
- def operator; :== end
- end
-
- class Inequality < Equality
- def eval(row)
- operand1.eval(row) != operand2.eval(row)
- end
- end
-
- class GreaterThanOrEqualTo < Binary
- def operator; :>= end
- end
-
- class GreaterThan < Binary
- def operator; :> end
- end
-
- class LessThanOrEqualTo < Binary
- def operator; :<= end
- end
-
- class LessThan < Binary
- def operator; :< end
- end
-
- class Match < Binary
- def operator; :=~ end
- end
-
- class NotMatch < Binary
- def eval(row)
- operand1.eval(row) !~ operand2.eval(row)
- end
- end
-
- class In < Binary
- def eval(row)
- operand2.eval(row).include?(operand1.eval(row))
- end
- end
-
- class NotIn < Binary
- def eval(row)
- !(operand2.eval(row).include?(operand1.eval(row)))
- end
- end
- end
-end