是否有可能要求Gemfile以外的文件? [英] Is it possible to require files outside the Gemfile?
问题描述
例如,我正在开发一个gem,并且在开发过程中,我使用 pry
代替IRB,并使用 debugger
用于调试。但是,我不希望可能的贡献者必须安装它们(因为它们可能不需要它们)。我的第一个想法是把它们放在一个Bundler组中:
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
但我希望它是未安装的默认设置。在我的 Gemfile
中它们是 not ,但我仍然可以要求它们(如果它们存在于计算机上),那将是完美的。这个解决方案可以,因为我不在乎他们被锁定的版本。可以这样做吗?
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?
推荐答案
您可以将基于环境变量的条件添加到Gemfile中。例如:
You could add a conditional based on environment variables into the Gemfile. Example:
source :rubygems
gemspec
if ENV['WITH_EXTRAS'] == '1'
gem "pry"
gem "debugger"
end
如果您将环境变量设置为'1'
,则仅安装/加载gem。 WITH_EXTRAS = 1捆绑安装
。
The gems are then only installed/loaded, if you set the environment variable to '1'
e.g. WITH_EXTRAS=1 bundle install
.
这篇关于是否有可能要求Gemfile以外的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!