-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add caret operator. #7972
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
base: master
Are you sure you want to change the base?
Add caret operator. #7972
Conversation
|
Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality. We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below. If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack. For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide |
|
🤔 Any reason to not call it just |
The scheme followed by npm and composer seems to be not including the Either operator name, or some third option, is fine with me. |
For this use case I think what most people do is For gem maintainers, this hasn't been an issue either. If their So, for RubyGems, I am wondering if there really is a need for a |
|
I could imagine some situation where one of your dependencies has a bug that makes your library quite useless, so you want to force a working version of the dependency. Maybe to avoid user reports coming your way. If the minimum working version is not explicitly forced, users can of course still get the proper version of the subdependency through Overall, this would be a shortcut to things like |
|
Yeah I am also wondering if |
What was the end-user or developer problem that led to this PR?
Suppose a project has a requirement like this:
gem 'something', '~> 3.0'
So far, so good. Now, version 3.0.2 comes out with some critical security fix, and the project admins want to make sure everyone has it. They update the requirement to look like this:
gem 'something', '~> 3.0.2'
This seemingly works as intended - but there is a non-obvious difference in how the requirements operate. The first version matches anything between 3.0 and 4.0 - but the second only matches between 3.0.2 and 3.1.0.
This isn't a bug: the ~> operator works exactly as documented - but for many usecases, a caret operator would be helpful. This patch includes a ^> operator - basically, unlike ~>, which has a variable scope, ^> always matches from the specified version until the next major version.
This means that '^> 3.0.2' will match > 3.0.2 but < 4.0.0.
There is a similarly functioning ^ operator in npm, PHP's Composer, and Rust's Cargo - though that their equivalent of the ~> operator doesn't function exactly like RubyGems.
What is your fix for the problem, implemented in this PR?
Added a ^> operator.
Also added a bump_major method to Gem::Version, which makes the code in Gem::Requirement a bit cleaner, and is conceivably useful in other circumstances.
Several notes:
I don't know if ^> is the community preferred name; if people prefer ^ to more closely follow npm and friends, I'll gladly change.
I am not sure if bump_major is the best name for the method in Gem::Version; I had considered "next_major_version", but bump_major seemed to fit closer with current method names.
I will gladly submit an update to change either of those decisions.
Make sure the following tasks are checked