I'd like to conditionally set require: in my Gemfile definition depending on the environment to work in conjunction with Bundler.require. E.g. i'd like pry to be available in all environments but only have require: true set in development and test. I'm currently doing something like this:
# make pry available for anyone who wants it
# but not automatically required
# e.g. in a console
gem 'pry', require: false
# automatically require pry
# for easy usage in tests
group :development, :test do
gem 'pry', require: true
end
Which works but results in a nice warning regarding a duplicate gem definition:
Your Gemfile lists the gem pry (>= 0) more than once. You should probably keep only one of them. While it's not a problem now, it could cause errors if you change the version of just one of them later.
Alternately, I can try to do something like this:
gem 'pry', require: ENV["RACK_ENV"] != "production"
but that feels much less declarative (and a little gross).
To clarify,
Bundler.require in the development and test environments Bundler.requireYou use :require => false when you want the gem to be installed but not "required". If you are not planning to use 'pry' gem in production it doesn't make sense to even install it in production.
You can make a gem available to use in any environment by explicitly specifying it. E.g. Make pry available in development and test environments
group :development, :test do
gem 'pry'
end
Hope, this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With