5

I am working with a team of developers, and we are all using the same Gemfile from our repository. Because I am working on a Mac, and others are using Ubuntu, we have a Gemfile.local.example file in our repository as well that has the appropriate notification gems for each OS, all commented out.

I un-commented the gems for my OS and saved as a new file, not in version control, Gemfile.local. Now I would like "bundle install" to install gems from both files.

I can't find any good documentation on doing this.

dudeitsdevin90
  • 325
  • 2
  • 9
  • 2
    Possible duplicate of http://stackoverflow.com/questions/7962743/bundler-load-multiple-gemfiles – Conner Jul 19 '12 at 16:50

4 Answers4

7

Why not just have one Gemfile and use things like groups or use the :platform flag to only install some gems on OS X and others on Ubuntu?

Seems pretty unwieldy to have two Gemfiles. You can supply the Gemfile to use to bundle config (man page) if you really want to do that, I guess.

benilov
  • 1,234
  • 11
  • 11
Edd Morgan
  • 2,873
  • 17
  • 22
  • This is awesome, I was not aware of the platform option. I had been using conditionals in my Gemfile with a RUBY_PLATFORM constant. So much cleaner! – Peter Brown Jul 19 '12 at 16:55
  • Using the ':platform' flag does seem to be the most elegant solution, but it appears that 'platform :ruby' references OSX and Ubuntu, while 'platform :mswin, :mingw' references Windows. I need to specify between OSX and Ubuntu. [This page](http://yopefonic.wordpress.com/2011/06/23/multi-platform-ruby-development-with-bundler/) suggests using the RUBY_PLATFORM constant. Is there another way? – dudeitsdevin90 Jul 19 '12 at 18:40
5

I agree that using two Gemfiles is bad practice, and have found a solution that involves the RUBY_PLATFORM constant along with the platform flag in my Gemfile. This may not be the MOST elegant solution, but it does work for me.

Here is a chunk of my code for curious readers:

group :development, :test do
  # Mac OSX notifications
  gem 'growl_notify' if RUBY_PLATFORM.downcase.include?("darwin")
  gem 'growl' if RUBY_PLATFORM.downcase.include?("darwin")

  # Gnome notifications => aka for Linux
  gem 'libnotify' if RUBY_PLATFORM.downcase.include?("linux")

  # Guard-spork doesn't work with windows but it's
  # awesome for other Operating Systems.
  gem 'guard-spork' if RUBY_PLATFORM.downcase.include?('darwin') || RUBY_PLATFORM.downcase.include?('linux')

  # Windows Rubies (RubyInstaller)
  platforms :mswin, :mingw do
    # Windows notifications
    gem 'rb-notifu' 
  end
end
Community
  • 1
  • 1
dudeitsdevin90
  • 325
  • 2
  • 9
1

I'm not sure about the cross platform compatability (it looks like it only supports OS X), but RVM gemsets would be worth looking into. I use this on my mac at work and it works beautifully.

RVM allows me to create and use multiple gemset configurations by running the rvm use command. The gems are installed into the gemset that I'm currently using so you don't have to worry about conflicts in your global gemset.

https://rvm.io//

Josh Moore
  • 820
  • 7
  • 8
0

You should all be using the same Gemfile and a master Gemfile.lock should be circulating as well. At least this is the ideal.

Remember that you can use Ruby to differentiate which sections are loaded by Bundle.setup and you can use groups to define things that are only relevant to a particular platform.

The Gemfile.lock should represent the specific requirements for how the application is deployed. It's supposed to be in the version control system so there's no confusion on what version the application will launch with. If there's platform issues here, you should be careful about what you use, and where required, lock down dependencies to the :development group only.

tadman
  • 208,517
  • 23
  • 234
  • 262