At runtime, after package configuration is completed, and groups are applied, what is the best way to programmatically check if a given gem_name
is in a bundle?
While reading the source code, I found Bundler.definition
like
gem_name = 'banana' Bundler.definition.dependencies.map(&:name).include?(gem_name)
but the documentation cannot be found 1 I do not know if this use is recommended.
Update: it looks like Bundler::Definition#dependencies
returns all dependencies regardless of groups. As an alternative, I found Bundler::Runtime#dependencies_for
, which takes groups as arguments.
Bundler.load.dependencies_for(:default, Rails.env).map(&:name).include?(gem_name)
However, it seems like a bad idea to duplicate "group lists" on every call site. Ideally, I need a method in the Bundler
that does not require me to specify current groups.
1 Vendor web page and man page are command line oriented. I did not find any documentation on the Ruby Gem Public Ruby API. Comments in the source are useful, but oriented to data types, etc.
source share