Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport endless ranges in where #34906
Conversation
rails-bot
bot
added
the
activerecord
label
Jan 9, 2019
tenderlove
requested changes
Jan 9, 2019
@@ -639,6 +639,16 @@ class AttributeTest < Arel::Spec | |||
) | |||
end | |||
|
|||
it "can be constructed with a range implicitly ending at Infinity" do | |||
attribute = Attribute.new nil, nil | |||
node = attribute.between(0..) |
This comment has been minimized.
This comment has been minimized.
tenderlove
Jan 9, 2019
Member
I think this will give us a syntax error on 2.5. Can you conditionalize this test so we don't get build failures on 2.5?
This comment has been minimized.
This comment has been minimized.
gregnavis
Jan 9, 2019
Author
Contributor
Sure. The built actually failed for precisely this reason. I'll push an update tomorrow.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
gregnavis
Jan 10, 2019
Author
Contributor
D'oh, what I did won't work for syntax error
I can either:
- Come up with something that would work for syntax errors.
- Leave the check as it is and replace
0..
with0..nil
(they're equivalent). In Rubyies pre-2.6 the latter results in anArgumentError
exception.
@tenderlove what do you think?
gregnavis
force-pushed the
gregnavis:add-endless-ranges-to-activerecord
branch
from
3a67c12
to
20b108a
Jan 10, 2019
sikachu
reviewed
Jan 11, 2019
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(0..) |
This comment has been minimized.
This comment has been minimized.
sikachu
Jan 11, 2019
Member
May I suggest this?
node = attribute.between(0..) | |
node = attribute.between(eval("0..")) # Use eval for compatibility with Ruby < 2.6 parser. |
This way Ruby parser in version < 2.6 will just overlook it.
This comment has been minimized.
This comment has been minimized.
gregnavis
force-pushed the
gregnavis:add-endless-ranges-to-activerecord
branch
2 times, most recently
from
905d11e
to
fbccf87
Jan 11, 2019
sikachu
reviewed
Jan 11, 2019
Would you mind checking CodeClimate? Looks like in the test, line 642 and 645 should both use double quote and not single quote. |
gregnavis
force-pushed the
gregnavis:add-endless-ranges-to-activerecord
branch
from
fbccf87
to
7110dbe
Jan 11, 2019
This comment has been minimized.
This comment has been minimized.
@tenderlove @sikachu thanks for comments! The build is green now. Please have another look. |
sikachu
approved these changes
Jan 11, 2019
I think this is good to merge. @tenderlove, please! |
gregnavis commentedJan 9, 2019
•
edited
Summary
This commit adds support for endless ranges, e.g.
(1..)
, that were added in Ruby 2.6. They're functionally equivalent to explicitly specifyingFloat::INFINITY
as the end of the range.Specifically:
is equivalent to
Other Information
Only the end of a range can be omitted. Trying
(..1)
results in a syntax error so there's no need to add support for implicit-Float::INFINITY
.Alternative Implementation
We could modify
other
at the beginning ofbetween
and replacenil
withFloat::INFINITY
(or even support-Float::INFINITY
) so that there'd be no changes to conditions inif
statements below + we would be able to supportnil..1
(equivalent to-Float::INFINITY..1
).Please let me know if you find this preferable and I'll update the PR.