1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

build quoted nodes in factory methods

This commit is contained in:
Aaron Patterson 2014-03-24 17:18:56 -07:00
parent d38352ef9e
commit 6d47c4cae5
3 changed files with 24 additions and 15 deletions

View file

@ -62,6 +62,13 @@ module Arel
end
def nil?; @val.nil?; end
def eql? other
self.class == other.class &&
self.val == other.val &&
self.attribute == other.attribute
end
alias :== :eql?
end
class Quoted < Arel::Nodes::Unary # :nodoc:
@ -69,7 +76,7 @@ module Arel
def self.build_quoted other, attribute = nil
case other
when Arel::Nodes::Node, Arel::Attributes::Attribute
when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Nodes::SelectStatement, Arel::Table, Arel::Nodes::BindParam
other
else
case attribute

View file

@ -51,8 +51,6 @@ module Arel
::Arel::Visitors::DepthFirst.new(block).accept self
end
def cast_reference?; false; end # :nodoc:
end
end
end

View file

@ -1,7 +1,7 @@
module Arel
module Predications
def not_eq other
Nodes::NotEqual.new self, other
Nodes::NotEqual.new self, Nodes.build_quoted(other, self)
end
def not_eq_any others
@ -44,8 +44,10 @@ module Arel
else
Nodes::Between.new(self, Nodes::And.new([Nodes.build_quoted(other.begin, self), Nodes.build_quoted(other.end, self)]))
end
else
when Array
Nodes::In.new self, other.map { |x| Nodes.build_quoted(x, self) }
else
Nodes::In.new self, Nodes.build_quoted(other, self)
end
end
@ -65,22 +67,24 @@ module Arel
if other.begin == -Float::INFINITY && other.end == Float::INFINITY
Nodes::In.new self, []
elsif other.end == Float::INFINITY
Nodes::LessThan.new(self, other.begin)
Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self))
elsif other.begin == -Float::INFINITY && other.exclude_end?
Nodes::GreaterThanOrEqual.new(self, other.end)
Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self))
elsif other.begin == -Float::INFINITY
Nodes::GreaterThan.new(self, other.end)
Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self))
elsif other.exclude_end?
left = Nodes::LessThan.new(self, other.begin)
right = Nodes::GreaterThanOrEqual.new(self, other.end)
left = Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self))
right = Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self))
Nodes::Or.new left, right
else
left = Nodes::LessThan.new(self, other.begin)
right = Nodes::GreaterThan.new(self, other.end)
left = Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self))
right = Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self))
Nodes::Or.new left, right
end
when Array
Nodes::NotIn.new self, other.map { |x| Nodes.build_quoted(x, self) }
else
Nodes::NotIn.new self, other
Nodes::NotIn.new self, Nodes.build_quoted(other, self)
end
end
@ -117,7 +121,7 @@ module Arel
end
def gteq right
Nodes::GreaterThanOrEqual.new self, right
Nodes::GreaterThanOrEqual.new self, Nodes.build_quoted(right, self)
end
def gteq_any others
@ -129,7 +133,7 @@ module Arel
end
def gt right
Nodes::GreaterThan.new self, right
Nodes::GreaterThan.new self, Nodes.build_quoted(right, self)
end
def gt_any others