diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-06 13:42:31 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-06 13:42:31 -0300 |
commit | 6ba88266720049415e91a5348e78657e2f85d848 (patch) | |
tree | 60c23fccb8e530b5f32664063a70ab29641adae7 /lib | |
parent | 8eb2a7a75bc977b9c4c8311952a142dfa1565238 (diff) | |
parent | 493cc80fd5f59ba213d4ce54b707c16604e558b8 (diff) | |
download | rails-6ba88266720049415e91a5348e78657e2f85d848.tar.gz rails-6ba88266720049415e91a5348e78657e2f85d848.tar.bz2 rails-6ba88266720049415e91a5348e78657e2f85d848.zip |
Merge pull request #284 from Octember/master
Cleaned up some edge cases with infinity in predications.rb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/predications.rb | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb index 2ef4837548..78cd87d430 100644 --- a/lib/arel/predications.rb +++ b/lib/arel/predications.rb @@ -29,14 +29,16 @@ module Arel when Arel::SelectManager Arel::Nodes::In.new(self, other.ast) when Range - if other.begin == -Float::INFINITY && other.end == Float::INFINITY - Nodes::NotIn.new self, [] + if other.begin == -Float::INFINITY + if other.end == Float::INFINITY + Nodes::NotIn.new self, [] + elsif other.exclude_end? + Nodes::LessThan.new(self, Nodes.build_quoted(other.end, self)) + else + Nodes::LessThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) + end elsif other.end == Float::INFINITY Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.begin, self)) - elsif other.begin == -Float::INFINITY && other.exclude_end? - Nodes::LessThan.new(self, Nodes.build_quoted(other.end, self)) - elsif other.begin == -Float::INFINITY - Nodes::LessThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) elsif other.exclude_end? left = Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.begin, self)) right = Nodes::LessThan.new(self, Nodes.build_quoted(other.end, self)) @@ -64,21 +66,23 @@ module Arel when Arel::SelectManager Arel::Nodes::NotIn.new(self, other.ast) when Range - if other.begin == -Float::INFINITY && other.end == Float::INFINITY - Nodes::In.new self, [] - elsif other.end == Float::INFINITY + if other.begin == -Float::INFINITY # The range begins with negative infinity + if other.end == Float::INFINITY + Nodes::In.new self, [] # The range is infinite, so return an empty range + elsif other.exclude_end? + Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) + else + Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self)) + end + elsif other.end == Float::INFINITY Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self)) - elsif other.begin == -Float::INFINITY && other.exclude_end? - Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) - elsif other.begin == -Float::INFINITY - Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self)) - elsif other.exclude_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, Nodes.build_quoted(other.begin, self)) - right = Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self)) + if other.exclude_end? + right = Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) + else + right = Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self)) + end Nodes::Or.new left, right end when Array |