diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/algebra/predicates.rb | 62 | ||||
-rw-r--r-- | lib/arel/algebra/primitives/attribute.rb | 14 | ||||
-rw-r--r-- | lib/arel/engines/memory/predicates.rb | 50 | ||||
-rw-r--r-- | lib/arel/engines/sql/predicates.rb | 72 |
4 files changed, 102 insertions, 96 deletions
diff --git a/lib/arel/algebra/predicates.rb b/lib/arel/algebra/predicates.rb index 72167c2b27..8a0b41fa18 100644 --- a/lib/arel/algebra/predicates.rb +++ b/lib/arel/algebra/predicates.rb @@ -1,41 +1,43 @@ module Arel - class Predicate - def or(other_predicate) - Or.new(self, other_predicate) - end + module Predicates + class Predicate + def or(other_predicate) + Or.new(self, other_predicate) + end - def and(other_predicate) - And.new(self, other_predicate) + def and(other_predicate) + And.new(self, other_predicate) + end end - end - class Binary < Predicate - attributes :operand1, :operand2 - deriving :initialize + class Binary < Predicate + attributes :operand1, :operand2 + deriving :initialize - def ==(other) - self.class === other and - @operand1 == other.operand1 and - @operand2 == other.operand2 - end + def ==(other) + self.class === other and + @operand1 == other.operand1 and + @operand2 == other.operand2 + end - def bind(relation) - self.class.new(operand1.find_correlate_in(relation), operand2.find_correlate_in(relation)) + def bind(relation) + self.class.new(operand1.find_correlate_in(relation), operand2.find_correlate_in(relation)) + end end - end - class Equality < Binary - def ==(other) - Equality === other and - ((operand1 == other.operand1 and operand2 == other.operand2) or - (operand1 == other.operand2 and operand2 == other.operand1)) + class Equality < Binary + def ==(other) + Equality === other and + ((operand1 == other.operand1 and operand2 == other.operand2) or + (operand1 == other.operand2 and operand2 == other.operand1)) + end end - end - class GreaterThanOrEqualTo < Binary; end - class GreaterThan < Binary; end - class LessThanOrEqualTo < Binary; end - class LessThan < Binary; end - class Match < Binary; end - class In < Binary; end + class GreaterThanOrEqualTo < Binary; end + class GreaterThan < Binary; end + class LessThanOrEqualTo < Binary; end + class LessThan < Binary; end + class Match < Binary; end + class In < Binary; end + end end diff --git a/lib/arel/algebra/primitives/attribute.rb b/lib/arel/algebra/primitives/attribute.rb index 44a2f41733..40a7d61a53 100644 --- a/lib/arel/algebra/primitives/attribute.rb +++ b/lib/arel/algebra/primitives/attribute.rb @@ -82,31 +82,31 @@ module Arel module Predications def eq(other) - Equality.new(self, other) + Predicates::Equality.new(self, other) end def lt(other) - LessThan.new(self, other) + Predicates::LessThan.new(self, other) end def lteq(other) - LessThanOrEqualTo.new(self, other) + Predicates::LessThanOrEqualTo.new(self, other) end def gt(other) - GreaterThan.new(self, other) + Predicates::GreaterThan.new(self, other) end def gteq(other) - GreaterThanOrEqualTo.new(self, other) + Predicates::GreaterThanOrEqualTo.new(self, other) end def matches(regexp) - Match.new(self, regexp) + Predicates::Match.new(self, regexp) end def in(array) - In.new(self, array) + Predicates::In.new(self, array) end end include Predications diff --git a/lib/arel/engines/memory/predicates.rb b/lib/arel/engines/memory/predicates.rb index 03d4f25b0a..dd2559c70f 100644 --- a/lib/arel/engines/memory/predicates.rb +++ b/lib/arel/engines/memory/predicates.rb @@ -1,35 +1,37 @@ module Arel - class Binary < Predicate - def eval(row) - operand1.eval(row).send(operator, operand2.eval(row)) + module Predicates + class Binary < Predicate + def eval(row) + operand1.eval(row).send(operator, operand2.eval(row)) + end end - end - class Equality < Binary - def operator; :== end - end + class Equality < Binary + def operator; :== end + end - class GreaterThanOrEqualTo < Binary - def operator; :>= end - end + class GreaterThanOrEqualTo < Binary + def operator; :>= end + end - class GreaterThan < Binary - def operator; :> end - end + class GreaterThan < Binary + def operator; :> end + end - class LessThanOrEqualTo < Binary - def operator; :<= end - end + class LessThanOrEqualTo < Binary + def operator; :<= end + end - class LessThan < Binary - def operator; :< end - end + class LessThan < Binary + def operator; :< end + end - class Match < Binary - def operator; :=~ end - end + class Match < Binary + def operator; :=~ end + end - class In < Binary - def operator; :include? end + class In < Binary + def operator; :include? end + end end end diff --git a/lib/arel/engines/sql/predicates.rb b/lib/arel/engines/sql/predicates.rb index b84c183c1d..e563a9ba3e 100644 --- a/lib/arel/engines/sql/predicates.rb +++ b/lib/arel/engines/sql/predicates.rb @@ -1,51 +1,53 @@ module Arel - class Binary < Predicate - def to_sql(formatter = nil) - "#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}" + module Predicates + class Binary < Predicate + def to_sql(formatter = nil) + "#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}" + end end - end - class CompoundPredicate < Binary - def to_sql(formatter = nil) - "(#{operand1.to_sql(formatter)} #{predicate_sql} #{operand2.to_sql(formatter)})" + class CompoundPredicate < Binary + def to_sql(formatter = nil) + "(#{operand1.to_sql(formatter)} #{predicate_sql} #{operand2.to_sql(formatter)})" + end end - end - class Or < CompoundPredicate - def predicate_sql; "OR" end - end + class Or < CompoundPredicate + def predicate_sql; "OR" end + end - class And < CompoundPredicate - def predicate_sql; "AND" end - end + class And < CompoundPredicate + def predicate_sql; "AND" end + end - class Equality < Binary - def predicate_sql - operand2.equality_predicate_sql + class Equality < Binary + def predicate_sql + operand2.equality_predicate_sql + end end - end - class GreaterThanOrEqualTo < Binary - def predicate_sql; '>=' end - end + class GreaterThanOrEqualTo < Binary + def predicate_sql; '>=' end + end - class GreaterThan < Binary - def predicate_sql; '>' end - end + class GreaterThan < Binary + def predicate_sql; '>' end + end - class LessThanOrEqualTo < Binary - def predicate_sql; '<=' end - end + class LessThanOrEqualTo < Binary + def predicate_sql; '<=' end + end - class LessThan < Binary - def predicate_sql; '<' end - end + class LessThan < Binary + def predicate_sql; '<' end + end - class Match < Binary - def predicate_sql; 'LIKE' end - end + class Match < Binary + def predicate_sql; 'LIKE' end + end - class In < Binary - def predicate_sql; operand2.inclusion_predicate_sql end + class In < Binary + def predicate_sql; operand2.inclusion_predicate_sql end + end end end |