diff options
author | Noah Lindner <nwlindner@gmail.com> | 2014-06-01 15:57:45 -0700 |
---|---|---|
committer | Noah Lindner <nwlindner@gmail.com> | 2014-06-01 15:57:45 -0700 |
commit | 493cc80fd5f59ba213d4ce54b707c16604e558b8 (patch) | |
tree | bc0330fbb34ac31f28586644b1f0a7f12ef62896 | |
parent | 6a7e94ae5c29542aa3b3e33a7fc77a1546ec793f (diff) | |
download | rails-493cc80fd5f59ba213d4ce54b707c16604e558b8.tar.gz rails-493cc80fd5f59ba213d4ce54b707c16604e558b8.tar.bz2 rails-493cc80fd5f59ba213d4ce54b707c16604e558b8.zip |
Cleaned up some edge cases with infinity, the logic seems more intuitive now
-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 |