Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a gem in Rails 3 without referencing it in the Gemfile

I'm wondering how to make a gem accessible in a Rails 3 app without putting a reference to it in the gemfile. I want to do this with ruby-debug (I'm using ruby-debug19). I use this to debug, but not everybody on my team does and forcing the dependency just so I can use it doesn't seem very diplomatic. Is there another way?

If it ends up mattering, I'm using Rails3, Bundler 1.0.0, Ruby 1.9.2, RVM, OSX Snow Leopard

On a side note, I had thought about using the gemfile group feature, but this doesn't feel right either. Groups seem great for things like factory_girl where there is an actual dependency albeit only in specfic environments, but with ruby-debug there is no real need for it to be there unless you want to use it.

like image 985
Blake Taylor Avatar asked Sep 20 '10 15:09

Blake Taylor


2 Answers

This is really ugly and it does not pull it out of your gemfile, but I do this in my Gemfile so I can use 2 different sources for a gem in different environments:

if ENV['MY_RDEBUG_VAR'] == "i_want_to_use_rdebug"
  gem "ruby-debug"
end

Just make it an obscure environment variable that only you would set on your system. That way, your coworkers will not have the env var set and the gem will never be installed or loaded for them.

like image 179
johnmcaliley Avatar answered Sep 23 '22 19:09

johnmcaliley


AFAIK you can't because Rails 3 isolates system Gems.

My suggestion is to add the Gem in the Gemfile with the :require => false option so it is included, installed but never loaded. Then, in your app, require the gem manually.

Or you can try to bundle it in your project, within the vendor folder (there should be a folder for Gems) and ignore the specific gem folder in your SCM so that your co-workers won't be affected.

like image 25
Simone Carletti Avatar answered Sep 22 '22 19:09

Simone Carletti