2017-02-13 13:58:58 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-24 01:45:50 -05:00
|
|
|
|
2018-02-24 02:41:47 -05:00
|
|
|
module Arel # :nodoc: all
|
2010-08-16 20:26:12 -04:00
|
|
|
module Nodes
|
2016-10-04 18:28:49 -04:00
|
|
|
class Binary < Arel::Nodes::NodeExpression
|
2010-08-16 20:26:12 -04:00
|
|
|
attr_accessor :left, :right
|
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def initialize(left, right)
|
2013-05-17 18:43:54 -04:00
|
|
|
super()
|
2010-08-16 20:26:12 -04:00
|
|
|
@left = left
|
|
|
|
@right = right
|
|
|
|
end
|
2010-12-14 23:31:49 -05:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def initialize_copy(other)
|
2010-12-14 23:31:49 -05:00
|
|
|
super
|
|
|
|
@left = @left.clone if @left
|
|
|
|
@right = @right.clone if @right
|
|
|
|
end
|
2012-08-18 22:33:25 -04:00
|
|
|
|
|
|
|
def hash
|
2014-10-23 16:10:33 -04:00
|
|
|
[self.class, @left, @right].hash
|
2012-08-18 22:33:25 -04:00
|
|
|
end
|
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def eql?(other)
|
2012-08-18 22:33:25 -04:00
|
|
|
self.class == other.class &&
|
|
|
|
self.left == other.left &&
|
|
|
|
self.right == other.right
|
|
|
|
end
|
|
|
|
alias :== :eql?
|
2010-08-16 20:26:12 -04:00
|
|
|
end
|
2010-12-14 21:13:06 -05:00
|
|
|
|
2020-03-10 13:20:32 -04:00
|
|
|
module FetchAttribute
|
|
|
|
def fetch_attribute
|
|
|
|
if left.is_a?(Arel::Attributes::Attribute)
|
|
|
|
yield left
|
|
|
|
elsif right.is_a?(Arel::Attributes::Attribute)
|
|
|
|
yield right
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Between < Binary; include FetchAttribute; end
|
2020-06-14 01:35:25 -04:00
|
|
|
|
|
|
|
class GreaterThan < Binary
|
|
|
|
include FetchAttribute
|
|
|
|
|
|
|
|
def invert
|
|
|
|
Arel::Nodes::LessThanOrEqual.new(left, right)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class GreaterThanOrEqual < Binary
|
|
|
|
include FetchAttribute
|
|
|
|
|
|
|
|
def invert
|
|
|
|
Arel::Nodes::LessThan.new(left, right)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class LessThan < Binary
|
|
|
|
include FetchAttribute
|
|
|
|
|
|
|
|
def invert
|
|
|
|
Arel::Nodes::GreaterThanOrEqual.new(left, right)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class LessThanOrEqual < Binary
|
|
|
|
include FetchAttribute
|
|
|
|
|
|
|
|
def invert
|
|
|
|
Arel::Nodes::GreaterThan.new(left, right)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-19 03:18:50 -04:00
|
|
|
class IsDistinctFrom < Binary
|
|
|
|
include FetchAttribute
|
|
|
|
|
|
|
|
def invert
|
|
|
|
Arel::Nodes::IsNotDistinctFrom.new(left, right)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class IsNotDistinctFrom < Binary
|
|
|
|
include FetchAttribute
|
|
|
|
|
|
|
|
def invert
|
|
|
|
Arel::Nodes::IsDistinctFrom.new(left, right)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-14 01:35:25 -04:00
|
|
|
class NotEqual < Binary
|
|
|
|
include FetchAttribute
|
|
|
|
|
|
|
|
def invert
|
|
|
|
Arel::Nodes::Equality.new(left, right)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class NotIn < Binary
|
|
|
|
include FetchAttribute
|
|
|
|
|
|
|
|
def invert
|
|
|
|
Arel::Nodes::In.new(left, right)
|
|
|
|
end
|
|
|
|
end
|
2020-03-10 13:20:32 -04:00
|
|
|
|
|
|
|
class Or < Binary
|
|
|
|
def fetch_attribute(&block)
|
|
|
|
left.fetch_attribute(&block) && right.fetch_attribute(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-14 21:13:06 -05:00
|
|
|
%w{
|
|
|
|
As
|
2010-12-15 00:06:16 -05:00
|
|
|
Assignment
|
|
|
|
Join
|
2011-01-20 14:56:08 -05:00
|
|
|
Union
|
|
|
|
UnionAll
|
2011-01-22 09:16:53 -05:00
|
|
|
Intersect
|
|
|
|
Except
|
2010-12-14 21:13:06 -05:00
|
|
|
}.each do |name|
|
2010-12-15 00:06:16 -05:00
|
|
|
const_set name, Class.new(Binary)
|
2010-12-14 21:13:06 -05:00
|
|
|
end
|
2010-08-16 20:26:12 -04:00
|
|
|
end
|
|
|
|
end
|