Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gemfile: A better way to conditionally declare local or remote gems for multiple developers

Tags:

bundler

Our group has several people, any number of which may be working on any combination of gems. Currently, our Gemfile has stuff like this:

gem 'awesome-gem', :git => '[email protected]:somebody/awesome-gem.git'
# gem 'awesome-gem', :path => '/Users/developer-A/workspace/awesome-gem'

# gem 'rad-gem', :git => '[email protected]:somebody/rad-gem.git', :branch => 'release'
gem 'rad-gem', :path => '/some/path/specific-to/developer-B/rad-gem'

So developer-A was working on awesome-gem locally, and when they finished up, they just replaced their :path the gem's :git location and committed both to version control. developer-B and C do the same thing for rad-gem, each has a different :path in their locally modified Gemfile and if the Gemfile every has real changes, they have to undo their local :path setup, commit, undo to point back to their local version of rad-gem, etc.

This is both a pain and ugly, so I tried to come up with a better solution but the best I could come up with is something like this:

if ENV['RADGEM_PATH']
  gem 'rad-gem', :path => ENV['RADGEM_PATH']
else
  gem 'rad-gem', :git => '[email protected]:somebody/rad-gem.git', :branch => 'release'
end

This allows developer-B and C to set their own rad-gem path while removing much of the pain mentioned above. however, it is still ugly and I'm wondering if there is a better way to do this, possibly using groups?

like image 645
ynkr Avatar asked Feb 20 '12 23:02

ynkr


People also ask

What does a Gemfile do?

A Gemfile is a file we create which is used for describing gem dependencies for Ruby programs. A gem is a collection of Ruby code that we can extract into a “collection” which we can call later. It lets you specify which gems you want to use, and which versions of these gems to use.

Should I Gemfile lock version?

You should always include your Gemfile. lock if you are writing an application. The community seems to (largely) agree that you should include it in any Gems you create as well.

Where do I put 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 is Gemfile lock generated?

Gemfile. lock is automatically generated when you run bundle install or bundle update . It should never be edited manually.


1 Answers

Update (current)

A recent update to bunder now provides local git repos. This is the current way of solving this problem. Thank you sekrett

Update (outdated)

If you have Bundler >= 1.2, there is now a better way to do this. For example,

bundle config local.blog ~/Work/gems/blog

original answer (outdated)

A friend of mine on the rspec core team showed me the approach they used in the rspec-core Gemfile, so I guess I'll use that.

like image 71
ynkr Avatar answered Sep 21 '22 15:09

ynkr