Search code examples
rubyrubygemsversionbundler

Set version to latest version including prereleases in Gemfile


How do I specify a version constraint in a Gemfile, such that it always take the latest release including pre-releases of a gem.

Currently the library I work with has the latest stable release 2.0.0, and the latest pre-release 2.1.0.alpha.pre.171.

I could set the version constraint to >=2.1.0.alpha.pre.171 or just >=2.1.0.a, as I understand it. But would that also include future pre releases such as >=2.2.0.alpha.pre.1 or even >=3.0.0.alpha.pre.1 as well as future stable versions such as 3.0.0? And would that always resolve to the latest version?

Disclaimer: To not be misunderstood, this is not for any productive dependency management. The idea is to have a demo up an running, which should always include the latest features and as well should crash if the latest pre-release is broken.


Solution

  • This is a very bad idea in a nutshell, but it’s very easy to check:

    %w|2.1.0.alpha.pre.171
       2.1.0
       2.2.0.alpha.pre.1
       3.0.0.alpha.pre.1|.map(&Gem::Version.method(:new)).sort
    #⇒ [
    #   [0] #<Gem::Version "2.1.0.alpha.pre.171">,
    #   [1] #<Gem::Version "2.1.0">,
    #   [2] #<Gem::Version "2.2.0.alpha.pre.1">,
    #   [3] #<Gem::Version "3.0.0.alpha.pre.1">
    # ]
    

    So, yes, >= will work for any new release, including 2.1.0.