aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/arel/predications.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-01-03 09:46:42 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-01-08 16:45:17 +0900
commit7f856c3c8db71e2600d6a84bbc6510eb4ddd0418 (patch)
tree0a88d5d29152838ecc9495e784f5b6e68aa2b725 /activerecord/lib/arel/predications.rb
parenta75dea08225285eec5fc199684cd1a51853d2845 (diff)
downloadrails-7f856c3c8db71e2600d6a84bbc6510eb4ddd0418.tar.gz
rails-7f856c3c8db71e2600d6a84bbc6510eb4ddd0418.tar.bz2
rails-7f856c3c8db71e2600d6a84bbc6510eb4ddd0418.zip
Consolidate the duplicated code that building range predicate
This slightly change the code in the Arel to allow +/-INFINITY as open ended since the Active Record expects that behavior. See 5ecbeda.
Diffstat (limited to 'activerecord/lib/arel/predications.rb')
-rw-r--r--activerecord/lib/arel/predications.rb20
1 files changed, 8 insertions, 12 deletions
diff --git a/activerecord/lib/arel/predications.rb b/activerecord/lib/arel/predications.rb
index 77502dd199..28679ae892 100644
--- a/activerecord/lib/arel/predications.rb
+++ b/activerecord/lib/arel/predications.rb
@@ -35,15 +35,15 @@ module Arel # :nodoc: all
end
def between(other)
- if equals_quoted?(other.begin, -Float::INFINITY)
- if equals_quoted?(other.end, Float::INFINITY)
+ if infinity?(other.begin)
+ if infinity?(other.end)
not_in([])
elsif other.exclude_end?
lt(other.end)
else
lteq(other.end)
end
- elsif equals_quoted?(other.end, Float::INFINITY)
+ elsif infinity?(other.end)
gteq(other.begin)
elsif other.exclude_end?
gteq(other.begin).and(lt(other.end))
@@ -81,15 +81,15 @@ Passing a range to `#in` is deprecated. Call `#between`, instead.
end
def not_between(other)
- if equals_quoted?(other.begin, -Float::INFINITY)
- if equals_quoted?(other.end, Float::INFINITY)
+ if infinity?(other.begin)
+ if infinity?(other.end)
self.in([])
elsif other.exclude_end?
gteq(other.end)
else
gt(other.end)
end
- elsif equals_quoted?(other.end, Float::INFINITY)
+ elsif infinity?(other.end)
lt(other.begin)
else
left = lt(other.begin)
@@ -238,12 +238,8 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
others.map { |v| quoted_node(v) }
end
- def equals_quoted?(maybe_quoted, value)
- if maybe_quoted.is_a?(Nodes::Quoted)
- maybe_quoted.val == value
- else
- maybe_quoted == value
- end
+ def infinity?(value)
+ value.respond_to?(:infinite?) && value.infinite?
end
end
end