Lock down which project is using which Ruby gems, on which versions, with Bundler! Gem versions can be a pain to manage, especially if you or your team members work on multiple projects simultaneously, or if you work with contractors, temps, etc. Case in point: projects stall, people leave, and hand-offs often don’t include robust documentation.
Using Bundler is a great practice if you aren’t going to be working on a project forever and someone else will have to pick up where you left off, if you are working on one legacy project and one bleeding edge project, or if you frequently come back to projects after not working on them for some amount of time. Additionally, it can be difficult to get the right gems (dependencies on specific versions) if you have multiple versions on your system. Setting up, managing, and updating your ruby gem environment is a tedious task. Bundler can help!
http://bundler.io/
https://github.com/bundler/bundler
3. Manage the rubygems you
need…
“Bundler makes sure Ruby applications run
the same code on every machine”
From https://github.com/bundler/bundler
4. and their dependencies!
“and Bundler makes it easy to make sure
that your application has the dependencies
it needs to start up and run without errors.”
From http://bundler.io/
5. These are
a few of my
favorite things!
http://bplusmovieblog.files.wordpress.com/2013/10/the-sound-of-music-25.png
7. If you are...
On" developer, working on on" project
On" developer, working on man# projects
On! of man" developers, working on on! project
On! of man" developers, working on man" projects
8. Best Practices
Create one bundle per theme
Add gems to the Gemfile, not the
Gemfile.lock
Include ALL the gems you are using
on the theme in the bundle
9. Best Practices
Specify the version of the gem if you
know which one you need, otherwise
you can let Bundler handle it
Update gems using Bundler, not
manually
Once you have the bundle set up, use it!
10. Recommendations
State “require/bundler” in config.rb or set up
a bash alias so that you don’t have to type
“bundle exec…”
Use “chruby” to manage your system’s ruby
version (https://github.com/postmodern/chruby)
Add the ruby version your gems use to your
Gemfile
Bundler is a gem to manage gems. It’s a dependency manager so to speak, not a package manager. You may be thinking that it is similar to composer for PHP, and Composer is “strongly inspired by node's npm and ruby's bundler”.
Bundler tracks the theme's code and the rubygems it needs to run, so that a theme will always have the exact gems that it needs to compile.
It does this by managing the gems that the application depends on.
Given a list of gems, it can automatically download and install those gems, as well as any other gems needed by the gems that are listed.
Before installing gems, it checks the versions of every gem to make sure that they are compatible, and can all be loaded at the same time.
After the gems have been installed, Bundler can help you update some or all of them when new versions become available.
Finally, it records the exact versions that have been installed, so that others can install the exact same gems.
Well documented
Well supported
It helps me do my work and doesn’t get in my way
Rubygem versions and their dependencies on other gems are a pain to manage.
This becomes more complex when you are working on multiple projects simultaneously that don’t necessarily require the same gems or the same version of a rubygem.
This is the nature of web development in it’s current form.
We have very little control no matter what we do, so it’s nice to have some tools that alleviate pain points
What happens if you get a new computer, or you want to update your version of Ruby?
What about if you are using a Mac and your new themer is going to be on a PC?
What if a project stalls, and you need to come back to it in 6 months, or if you launched a project and then get rehired later to do more work after time has passed?
If you are using gems in your theme, even it it is just sass and compass, you could be using Bundler. You already have the dependency on Ruby, and you probably aren’t going to move away from Sass if you are already using it so let Bundler help you out.
If you or your team members work if you work with contractors, temps, people jumping on and off projects because of resourcing.
Case in point: projects stall, people leave, and hand-offs often don’t include robust documentation.
Using Bundler is a great practice if you aren’t going to be working on a project forever and someone else will have to pick up where you left off, if you are working on one legacy project and one bleeding edge project, or if you frequently come back to projects after not working on them for some amount of time.
One dev working on one project
If it is for a client, they might have someone else work on it in the future, and that someone will love you, if they are already ok with the Ruby dependency, that you saved them time.
They can get right to work by installing the bundle included.
Can’t tell what the future holds, you may be working on another project soon
One dev working on many projects
Switching back and forth, want to keep your gem environment tidy. You can have local gems on your system, but may not be using those on a project, and what
One of Many devs working on one project
You might need to work with contractors, interns, a new hire, etc.
I’m one person working on one project, but other devs who don’t necessarily work on the theme may need to.
We don’t compile on the server, so when our team lead does a release, he merges branches, of the theme, and then recompiles, so he needs the bundle.
Many devs working on many projects
All of the above would apply, and I think this scenario will benefit the most by starting to use bundler
The bundle install command always does a conservative update, refusing to update gems (or their dependencies) that you have not explicitly changed in the Gemfile.
Bundle update will update every gem in the Gemfile to the latest possible versions
There are some cases where you would want to update a Gem Without Modifying the Gemfile, but you would still use bundler to do that
Three main things
add require 'bundler/setup' it to your config.rb
One-time things
Need to install bundler gem once with “gem install bundler”
Then create your bundle with a Gemfile, then run bundle install and a Gemfile.lock is created
Include those new files in to source control
Maintenance
Going forward add, remove, or update gems in the Gemfile, and then run bundle install after you have made changes
Current gemfile
It includes:
the source of where I went to get the gems from
The ruby version, so that If the Gemfile is loaded on a different Ruby version, Bundler will raise an exception with an explanation.
The gems I use, with version numbers. The tilda arrow specifier means I want to use the version that is greater than or equal to the version specified, but less than the next release.
After creating or changing my Gemfile, I run bundle install, and this is my Gemfile.lock that is generated by bundler.