Permalink
Browse files

Support endless ranges in where

This commit adds support for endless ranges, e.g. (1..), that were added
in Ruby 2.6. They're functionally equivalent to explicitly specifying
Float::INFINITY as the end of the range.
  • Loading branch information...
gregnavis committed Jan 9, 2019
1 parent ea65d92 commit 7110dbea008dd4b80d1764003935a3c97ab10f57
@@ -1,3 +1,7 @@
* Add support for endless ranges introduces in Ruby 2.6.

*Greg Navis*

* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.

*Ryuta Kamizono*
@@ -36,14 +36,14 @@ def eq_all(others)

def between(other)
if infinity?(other.begin)
if infinity?(other.end)
if other.end.nil? || infinity?(other.end)
not_in([])
elsif other.exclude_end?
lt(other.end)
else
lteq(other.end)
end
elsif infinity?(other.end)
elsif other.end.nil? || infinity?(other.end)
gteq(other.begin)
elsif other.exclude_end?
gteq(other.begin).and(lt(other.end))
@@ -639,6 +639,18 @@ class AttributeTest < Arel::Spec
)
end

if Gem::Version.new("2.6.0") <= Gem::Version.new(RUBY_VERSION)
it "can be constructed with a range implicitly ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(eval("0..")) # Use eval for compatibility with Ruby < 2.6 parser

node.must_equal Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Casted.new(0, attribute)
)
end
end

it "can be constructed with a quoted range ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(0, ::Float::INFINITY, false))

0 comments on commit 7110dbe

Please sign in to comment.