-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Simpler version matching #1053
Comments
Why not use |
I wasn't aware it was considered acceptable for gems to load dependent gems at runtime that way. Regardless, that doesn't handle:
|
For gems listed as dependencies in your specification there is no need to I don't understand what your objections have to do with version matching via If you only want to run some code if some gem is available you still need to activate it via Changing the API for version matching doesn't handle conditional behavior for different versions of a gem either. The conditional code you need will likely dwarf the few characters of savings provided by a different API. This is handled fairly cleanly by a case statement after you've activated a gem, though: case Gem.loaded_specs['rake'].version
when Gem::Requirement.new '~> 10.0' then
# …
else
# …
end I wouldn't mind changing satisfied_by? to accept a Version or a Specification as it seems redundant to supply the version. I wouldn't mind fixing Specification#satisfies_requirement? to accept a Requirement, Requirement string or a Dependency ( I am not particularly fond of method_missing and Matcher APIs as they create extra garbage that needs to be cleaned up. I am not particularly fond of encouraging multiple version support as, in general, it does not encourage developers of libraries to commit to stable APIs. I prefer to follow in Matz's footsteps and make things you aren't supposed to do difficult. I recognize for projects that extend Rails that this is an unfair, but I fear that adding this to make it easier to interact with Rails will lead developers to think API churn is OK for their library that is orders of magnitude smaller. |
I will streamline satisfied_by? and satisfies_requirement? as described above. |
Proposal is:
|
This issue hasbeen ide for too long and nobody else has requested this feature, i'm going to close it for now |
Since Rubygems doesn't have a way to require optional runtime dependencies, when working on the Active Admin gem I've often been frustrated by the available methods to version-check a loaded gem.
It seems like the correct way is:
Not the easiest thing to remember, which I assume is why I often see developers comparing against the split version constants Rails provides:
Or, for gems that only have a version string:
Both approaches get more complex of you want to correctly deal with prerelease versions, or match a range of versions.
To make development easier I built an abstraction layer:
Would this general feature set be desirable for Rubygems itself?
The text was updated successfully, but these errors were encountered: