The pessimize gem <https://github.com/joonty/pessimize> is a command line
tool that adds pessimistic constraints (the operator that looks like ~>) to
the gems in your Gemfile.
Install: gem install pessimize
Why do you need this? You should be using "~> x.y" to limit the version
numbers of your gems, e.g. `gem "rails", "~> 4.2"`, otherwise bundle update
could potentially explodify your application when gems are updated without
restriction and introduce breaking changes.
This is particularly bad if you're returning to an old project that hasn't
been dusted off in a while. It's also a complete pain to manually update
your Gemfile, if you have more than a few gems.
With pessimize you can just run `pessimize`, which creates a backup of your
Gemfile and Gemfile.lock, gets all the existing versions of your gems and
writes out a new Gemfile with the version constraint added in. It will
insert version strings to each gem if you haven't added them, and will
update existing version strings if you have.
The first version completely reformatted the Gemfile, which wasn't great
for keeping things like comments or the order of gems that you specified.
The new version tokenizes the Gemfile, updates the relevant tokens, and
rewrites the file, so it should keep exactly the same formatting.
Give it a go! If you run into any issues, please open one on github
<https://github.com/joonty/pessimize/issues>. Contributions are of course
welcome and encouraged.