New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add .compare(a, b), .rcompare(a, b) #12
Conversation
1c17a92
to
b4b5039
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This CI failure in Ruby 1.8 looks like it might be unrelated to the changes in this branch. But just to be sure, care to look into why it might be failing?
ext/version_sorter/version_sorter.c
Outdated
} | ||
|
||
static VALUE | ||
rb_version_compare_r(VALUE rb_self, VALUE rb_version_a, VALUE rb_version_b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're exposing a low-level function, I don't think it makes sense to expose an alternate rcompare()
function that simply returns a negated result of compare()
. If the user needs to write low-level comparison code, then they can negate the result of compare()
themselves, and they don't strictly need rcompare()
. Does that make sense?
If we got rid of rcompare
, we wouldn't have the need for the internal rb_version_compare_1
function either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I simply added it for completeness.
b4b5039
to
7a77ebe
Compare
Looks like the build is failing because of the version of |
@keithamus Thanks for investigating! It's really a bummer that rubygems got downgraded from 2.4 to 2.0 between builds 😕 |
d81f4a2
to
99a9b3d
Compare
@mislav build now passing 🎉! Had to add |
Thanks for figuring this out! However, |
Okay noted. I'll probably go with something like the latter option. |
99a9b3d
to
fa36ce4
Compare
@@ -21,6 +21,10 @@ def test_sorts_versions_correctly | |||
|
|||
def test_sorts_versions_like_rubygems | |||
versions = %w(1.0.9.b 1.0.9 1.0.10 2.0 3.1.4.2 1.0.9a 2.0rc2 2.0-rc1) | |||
if (Gem.rubygems_version < Gem::Version.new('2.1.0')) | |||
# Old versions of RubyGems cannot parse semver versions like `2.0-rc1` | |||
versions.pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So rather than skip the test entirely, I just removed the offending version that cannot be parsed with older rubygems versions. So the test still runs and works - it just isn't as comprehensive for old versions.
Yay it actually passes now @mislav! |
I've exposed the
compare
function which give access to the raw sorting algo, useful when sorting on more than one dimension.