module Gem::BundlerSettings

Reads Bundler’s settings without loading Bundler, for the RubyGems commands that have to agree with something the user configured for Bundler.

Follows Bundler::Settings: the application config file wins over the BUNDLE_<NAME> environment variable, which wins over the user config file, and BUNDLE_IGNORE_CONFIG drops both files.

Public Class Methods

The configured value of Bundler setting name, or nil when it is unset.

# File lib/rubygems/bundler_settings.rb, line 17
def self.[](name)
  key = key_for name

  value = config_value app_config_file, key
  value = env_value key if value.nil?
  value = config_value user_config_file, key if value.nil?
  value
end

The value of Bundler setting name from the environment, or nil when the variable is unset or empty.

# File lib/rubygems/bundler_settings.rb, line 42
def self.env(name)
  env_value key_for(name)
end

The value of Bundler setting name from the config files only, application file first. Callers that read the environment variable ahead of the files pair this with .env.

# File lib/rubygems/bundler_settings.rb, line 31
def self.from_config_files(name)
  key = key_for name

  value = config_value app_config_file, key
  value.nil? ? config_value(user_config_file, key) : value
end

The gem dependencies file above the working directory, or nil when there is none. RubyGems recognizes a couple of names Bundler does not, so a directory holding only one of those is where the two disagree.

# File lib/rubygems/bundler_settings.rb, line 51
def self.gemfile_path
  gemfile = env_value "BUNDLE_GEMFILE"
  return gemfile if gemfile

  Gem::Util.traverse_parents(Dir.pwd) do |directory|
    found = Gem::GEM_DEP_FILES.find {|f| File.file?(f) }

    return File.join(directory, found) if found
  end

  nil
rescue SystemCallError
  # Dir.pwd raises when the working directory has been deleted, and when
  # an ancestor denies search to the current uid.
  nil
end