Skip to content

Instantly share code, notes, and snippets.

@svenfuchs
Created March 17, 2012 18:27
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save svenfuchs/2063855 to your computer and use it in GitHub Desktop.
Save svenfuchs/2063855 to your computer and use it in GitHub Desktop.
Developing with dependent local gem repositories

When developing an application where you have split out shared functionality to multiple dependent gem repositories can get cumbersome when you

  • need to edit the Gemfile in order to swap local :path sources with :git or just plain Rubygems sources,
  • then forget to bundle update,
  • wonder why your git repository is dirty and it's just the modified Gemfile and Gemfile.lock,
  • accidentally commit the Gemfile.lock with local :path sources bundled etc. etc.

So what about this strategy:

A. Create a file .Gemfile.local containing:

base = '..' # might need to tweak this according to your directory layout
instance_eval File.read(File.expand_path('Gemfile'))

B. Change your actual Gemfile to something like this:

base ||= 'git://github.com/travis-ci'
type = base[0, 2] == '..' ? :path : :git

gem 'foo', type => "#{base}/foo"
gem 'bar', type => "#{base}/bar"

C. Add the .Gemfile* to your .gitignore file so that other developers can create their own .Gemfile.local and tweak the base path to their directory layout.

D. Switch between both Gemfiles using export BUNDLE_GEMFILE=.Gemfile.local and export BUNDLE_GEMFILE=Gemfile

Voila. It is acceptably easy to switch between using local vs remote gem sources with just a few lines of code. Switching to local/remote gem sources won't dirty the git repository.

Obviously, if you've changed your Gemfile then you still need to remember to switch to remote gem sources and bundle update once you're done and want to commit/push changes (where you don't gitignore the Gemfile.lock).

What do you think?

@josevalim
Copy link

josevalim commented Mar 19, 2012 via email

@youngbrioche
Copy link

@josevalim Awesome work, dude! That'll come in really handy. But I was wondering if Bundler should limit a local override option to git-only dependencies. The problem of gems in development remains for rubygems-dependencies. I opened an issue, mainly for discussion at first: rubygems/bundler#1802.

@josevalim
Copy link

josevalim commented Mar 28, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment