views:

39

answers:

2

Our team uses different databases for each other, and we are using bundler so our Gemfile contains the repo creator's db connector(mysql)

I am using pg and due to a bit laziness and fear of breaking something, I don't want to use mysql, so I just add a gem "pg" in our Gemfile.

Of course, since we're using git, it will always show as a modified file, and we all use the Gemfile so we can't gitignore it or commit it with our changes.

Question is, how do we go about this? Is there a conditional in bundler or do I just have to declare that I'm using a certain gem someplace else?

A: 

You can use a group. Yehuda Katz explain it how here (taking in example the pg gem) http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/

hellvinz
A: 

Since Gemfile, like Rakefile, is just a chunk of Ruby, you can throw in conditionals if you think it will simplify your life. For instance:

if (Gem.available?('pg'))
  gem 'pg'
else
  gem 'mysql2'
end

Sometimes you have to do this for different Ruby versions as 1.8 and 1.9 sometimes need different gems.

tadman
what does Gem.available? do? does it check for the gems availability in your gem source or in your localhost?
corroded
It simply checks if it has already been installed, not if it is installable. Since you can create your own .gem files, it's technically possible to install a gem that isn't available anywhere, too.
tadman
i see i see. thanks!
corroded