2010-10-27 09:43:20 -04:00
|
|
|
module Arel
|
|
|
|
module Predications
|
|
|
|
def not_eq other
|
2014-03-24 20:18:56 -04:00
|
|
|
Nodes::NotEqual.new self, Nodes.build_quoted(other, self)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def not_eq_any others
|
|
|
|
grouping_any :not_eq, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def not_eq_all others
|
|
|
|
grouping_all :not_eq, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def eq other
|
2014-03-24 19:26:09 -04:00
|
|
|
Nodes::Equality.new self, Nodes.build_quoted(other, self)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def eq_any others
|
|
|
|
grouping_any :eq, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def eq_all others
|
2014-03-24 19:26:09 -04:00
|
|
|
grouping_all :eq, others.map { |x| Nodes.build_quoted(x, self) }
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
2014-10-25 08:24:18 -04:00
|
|
|
def between other
|
2014-10-25 08:38:56 -04:00
|
|
|
if other.begin == -Float::INFINITY
|
|
|
|
if other.end == Float::INFINITY
|
|
|
|
not_in([])
|
|
|
|
elsif other.exclude_end?
|
|
|
|
lt(other.end)
|
|
|
|
else
|
|
|
|
lteq(other.end)
|
|
|
|
end
|
|
|
|
elsif other.end == Float::INFINITY
|
|
|
|
gteq(other.begin)
|
|
|
|
elsif other.exclude_end?
|
|
|
|
gteq(other.begin).and(lt(other.end))
|
|
|
|
else
|
|
|
|
left = Nodes.build_quoted(other.begin, self)
|
|
|
|
right = Nodes.build_quoted(other.end, self)
|
|
|
|
Nodes::Between.new(self, left.and(right))
|
|
|
|
end
|
2014-10-25 08:24:18 -04:00
|
|
|
end
|
|
|
|
|
2010-10-27 09:43:20 -04:00
|
|
|
def in other
|
|
|
|
case other
|
|
|
|
when Arel::SelectManager
|
2010-12-07 13:46:30 -05:00
|
|
|
Arel::Nodes::In.new(self, other.ast)
|
2010-10-27 09:43:20 -04:00
|
|
|
when Range
|
2014-10-25 08:38:56 -04:00
|
|
|
if $VERBOSE
|
|
|
|
warn <<-eowarn
|
|
|
|
Passing a range to `#in` is deprecated. Call `#between`, instead.
|
|
|
|
eowarn
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
2014-10-25 08:38:56 -04:00
|
|
|
between(other)
|
2014-03-24 20:18:56 -04:00
|
|
|
when Array
|
2014-03-24 19:50:34 -04:00
|
|
|
Nodes::In.new self, other.map { |x| Nodes.build_quoted(x, self) }
|
2014-03-24 20:18:56 -04:00
|
|
|
else
|
|
|
|
Nodes::In.new self, Nodes.build_quoted(other, self)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def in_any others
|
|
|
|
grouping_any :in, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def in_all others
|
|
|
|
grouping_all :in, others
|
|
|
|
end
|
|
|
|
|
2014-10-25 08:38:56 -04:00
|
|
|
def not_between other
|
|
|
|
if other.begin == -Float::INFINITY # The range begins with negative infinity
|
|
|
|
if other.end == Float::INFINITY
|
|
|
|
self.in([])
|
|
|
|
elsif other.exclude_end?
|
|
|
|
gteq(other.end)
|
|
|
|
else
|
|
|
|
gt(other.end)
|
|
|
|
end
|
|
|
|
elsif other.end == Float::INFINITY
|
|
|
|
lt(other.begin)
|
|
|
|
else
|
|
|
|
left = lt(other.begin)
|
|
|
|
right = if other.exclude_end?
|
|
|
|
gteq(other.end)
|
|
|
|
else
|
|
|
|
gt(other.end)
|
|
|
|
end
|
|
|
|
left.or(right)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-27 09:43:20 -04:00
|
|
|
def not_in other
|
|
|
|
case other
|
|
|
|
when Arel::SelectManager
|
2010-12-07 13:46:30 -05:00
|
|
|
Arel::Nodes::NotIn.new(self, other.ast)
|
2010-10-27 09:43:20 -04:00
|
|
|
when Range
|
2014-10-25 08:38:56 -04:00
|
|
|
if $VERBOSE
|
|
|
|
warn <<-eowarn
|
|
|
|
Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
|
|
|
|
eowarn
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
2014-10-25 08:38:56 -04:00
|
|
|
not_between(other)
|
2014-03-24 20:18:56 -04:00
|
|
|
when Array
|
|
|
|
Nodes::NotIn.new self, other.map { |x| Nodes.build_quoted(x, self) }
|
2010-10-27 09:43:20 -04:00
|
|
|
else
|
2014-03-24 20:18:56 -04:00
|
|
|
Nodes::NotIn.new self, Nodes.build_quoted(other, self)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def not_in_any others
|
|
|
|
grouping_any :not_in, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def not_in_all others
|
|
|
|
grouping_all :not_in, others
|
|
|
|
end
|
|
|
|
|
2014-09-24 22:01:33 -04:00
|
|
|
def matches other, escape = nil
|
|
|
|
Nodes::Matches.new self, Nodes.build_quoted(other, self), escape
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
2014-09-24 22:01:33 -04:00
|
|
|
def matches_any others, escape = nil
|
|
|
|
grouping_any :matches, others, escape
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
2014-09-24 22:01:33 -04:00
|
|
|
def matches_all others, escape = nil
|
|
|
|
grouping_all :matches, others, escape
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
2014-09-24 22:01:33 -04:00
|
|
|
def does_not_match other, escape = nil
|
|
|
|
Nodes::DoesNotMatch.new self, Nodes.build_quoted(other, self), escape
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
2014-09-24 22:01:33 -04:00
|
|
|
def does_not_match_any others, escape = nil
|
|
|
|
grouping_any :does_not_match, others, escape
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
2014-09-24 22:01:33 -04:00
|
|
|
def does_not_match_all others, escape = nil
|
|
|
|
grouping_all :does_not_match, others, escape
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def gteq right
|
2014-03-24 20:18:56 -04:00
|
|
|
Nodes::GreaterThanOrEqual.new self, Nodes.build_quoted(right, self)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def gteq_any others
|
|
|
|
grouping_any :gteq, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def gteq_all others
|
|
|
|
grouping_all :gteq, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def gt right
|
2014-03-24 20:18:56 -04:00
|
|
|
Nodes::GreaterThan.new self, Nodes.build_quoted(right, self)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def gt_any others
|
|
|
|
grouping_any :gt, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def gt_all others
|
|
|
|
grouping_all :gt, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def lt right
|
2014-08-23 09:01:12 -04:00
|
|
|
Nodes::LessThan.new self, Nodes.build_quoted(right, self)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def lt_any others
|
|
|
|
grouping_any :lt, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def lt_all others
|
|
|
|
grouping_all :lt, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def lteq right
|
2014-08-23 09:01:12 -04:00
|
|
|
Nodes::LessThanOrEqual.new self, Nodes.build_quoted(right, self)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def lteq_any others
|
|
|
|
grouping_any :lteq, others
|
|
|
|
end
|
|
|
|
|
|
|
|
def lteq_all others
|
|
|
|
grouping_all :lteq, others
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2014-09-24 22:01:33 -04:00
|
|
|
def grouping_any method_id, others, *extras
|
|
|
|
nodes = others.map {|expr| send(method_id, expr, *extras)}
|
2011-04-18 12:05:19 -04:00
|
|
|
Nodes::Grouping.new nodes.inject { |memo,node|
|
|
|
|
Nodes::Or.new(memo, node)
|
2010-10-27 09:43:20 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-09-24 22:01:33 -04:00
|
|
|
def grouping_all method_id, others, *extras
|
|
|
|
nodes = others.map {|expr| send(method_id, expr, *extras)}
|
|
|
|
Nodes::Grouping.new Nodes::And.new(nodes)
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
end
|
2010-11-23 21:22:42 -05:00
|
|
|
end
|