在运行时,捆绑器设置完成后,并且groups http://bundler.io/v1.7/groups.html应用后,以编程方式检查给定值是否有效的最佳方法是什么?gem_name
是在捆绑包中吗?
通过阅读源码,我发现Bundler.definition https://github.com/bundler/bundler/blob/master/lib/bundler.rb#L152, e.g.
gem_name = 'banana'
Bundler.definition.dependencies.map(&:name).include?(gem_name)
but unable to find documentation1, I don't know if this is the recommended usage.
更新:看起来像Bundler::Definition#dependencies
返回所有依赖项,无论组如何。作为替代方案,我发现Bundler::Runtime#dependencies_for
它以组作为参数。
Bundler.load.dependencies_for(:default, Rails.env).map(&:name).include?(gem_name)
然而,在每个调用站点复制“组列表”似乎是一个坏主意。理想情况下,我想要一种方法Bundler
这不需要我指定当前组。
1 The bundler website and man page are focused on command-line usage. I have not found any documentation on the gem's public ruby API. Comments in the source are helpful, but focused on data types, etc.