For example, I'm developing a gem, and while I'm developing, I use pry
instead of IRB, and debugger
for debugging. However, I don't want possible contributors to have to install them (because they may not need them). My first idea was to put them in a Bundler group:
source :rubygems
gemspec
group :extras do
gem "pry"
gem "debugger"
end
And then people could use:
$ bundle install --without extras
But I want it to be a default that they're not installed. What would be perfect is that they're not in my Gemfile
, but that I can still require them (if they exist on the computer). This solution would be ok because I don't care at which version they're locked. Can it be done?
You could add a conditional based on environment variables into the Gemfile. Example:
The gems are then only installed/loaded, if you set the environment variable to
'1'
e.g.WITH_EXTRAS=1 bundle install
.bundle install
is "opt-out"—unless you specify--without some_group
, it installs everything.If you absolutely don't want to have a given gem in your Gemfile, you could just
gem install
that rogue gem outside of your bundle. Then it'll be visible to you underirb
and straightruby
(but obviously you'll get errors if you try torequire
it within code running underbundle exec
).