alphagov/puppet-rbenv — pull request #4 by dcarley (2013-06-19 08:15:59+00:00)
Title: [#51506059] Query current Bundler version

Be more intelligent about querying the currently installed version of
Bundler. Use `gem query` instead of `gem list|grep`, which allows us to
specifying a version string and returns true/false.

This now means that Bundler will be upgraded if the `bundler_version`
specified is greater than the version currently installed. Which is nice.

Some words about downgrades:

Downgrades are however still not supported. If we specify `bundler_version
=> 2` and then later `bundler_version => 1`, version 1 will be installed but
version 2 will always take precedence. The same will happen if a later
version of Bundler is installed by hand. Added docstrings to warn about
this.

Unfortunately gem doesn't provide an opposite to `gem cleanup`. The only
solution I see to this is to call a Ruby script (of our own) which would
iterate over `Gem::Specification.find_all`, compare versions using
`Gem::Version::Requirement`, and uninstall all but a single version.

Distributing it would be a pain though. It couldn't be a type/provider, as
it would use the RBENV_VERSION that Puppet is running as. It could be a new
gem which extends rubygem's own `Gem::Commands`, but even then it would need
to be installed for every version of Ruby available.

Another alternative:

We could simply query `bundle --version` and `gem install -a bundler` if the
string doesn't match our expectation. However we wouldn't be able to support
loose version requirements, like `>= 0` or `~> 1.2`, which seems like a
major disadvantage.