Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can Bundler/Gemfile be configured to use different gem sources during development?

I have a Sinatra application that requires another gem I'm developing locally. I'm having trouble configuring Bundler to use my local gem code during development but my vendored gem code in production.

Ideally I could do something like this, but Bundler doesn't allow you to specify the same gem twice:

# Doesn't work:
group :development do
  gem 'awesome', :path => "~/code/awesome"
end

group :production do
  gem 'awesome', :path => "vendor/gems/awesome-0.0.1"
end

In the meantime I've resorted to manually vendoring the gem & updating the gem source in the Gemfile every single time I deploy, which is quite a hassle. My workflow is this:

  1. Point to my local gem during development (gem 'awesome', :path => "~/code/awesome")
  2. When ready to deploy, unpack gem into vendor/gems
  3. Update Gemfile to point to vendored gem (gem 'awesome', :path => "vendor/gems/awesome-0.0.1")
  4. Run bundle install (to update Gemfile.lock)
  5. Deploy code
  6. Return to step 1.

What a hassle! I'd like to do something cleaner than simply writing Rake tasks to automate my current setup.

What's the best workflow for this scenario?

like image 401
Kyle Fox Avatar asked Sep 07 '11 17:09

Kyle Fox


People also ask

How do I set gem version in Gemfile?

There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .

What is gem in Gemfile?

A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile .

How does a Gemfile work?

Your gemfile is a list of all gems that you want to include in the project. It is used with bundler (also a gem) to install, update, remove and otherwise manage your used gems. These gems belong to development environment and the test environment since they are for testing the application.


1 Answers

There is a new feature that allows to do that, by simply specyfing local.gem_name config option, like:

bundle config local.rack ~/path/to/local/rack

This only works if the gem has a git repo and branch specified in the Gemfile.

See thr Bundler docs for more details: http://bundler.io/v1.3/bundle_config.html

like image 107
Piotr Sarnacki Avatar answered Oct 22 '22 01:10

Piotr Sarnacki