Module: Gem::BundlerSettings
| Relationships & Source Files | |
| Defined in: | lib/rubygems/bundler_settings.rb |
Overview
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_
Class Attribute Summary
- .ignore_config? ⇒ Boolean readonly private
Class Method Summary
-
.[](name)
The configured value of Bundler setting
name, or nil when it is unset. -
.env(name)
The value of Bundler setting
namefrom the environment, or nil when the variable is unset or empty. -
.from_config_files(name)
The value of Bundler setting
namefrom the config files only, application file first. -
.gemfile_path
The gem dependencies file above the working directory, or nil when there is none.
-
.app_config_file
private
The config file for the application, honoring BUNDLE_APP_CONFIG the way
Bundler.app_config_pathdoes: an absolute path is used as given, and a relative one is resolved against the directory holding the Gemfile. -
.config_value(file, key)
private
A config file that cannot be read or parsed leaves the setting unconfigured rather than aborting the gem command that only wanted to consult it.
- .env_value(key) private
- .key_for(name) private
- .user_config_file private
Class Attribute Details
.ignore_config? ⇒ Boolean (readonly, private)
[ GitHub ]
# File 'lib/rubygems/bundler_settings.rb', line 110
def self.ignore_config? !ENV["BUNDLE_IGNORE_CONFIG"].nil? end
Class Method Details
.[](name)
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
.app_config_file (private)
The config file for the application, honoring BUNDLE_APP_CONFIG the way
Bundler.app_config_path does: an absolute path is used as given, and a
relative one is resolved against the directory holding the Gemfile.
# File 'lib/rubygems/bundler_settings.rb', line 85
def self.app_config_file return if ignore_config? app_config = env_value("BUNDLE_APP_CONFIG") || ".bundle" return File.join(app_config, "config") if File.absolute_path?(app_config) gemfile = gemfile_path File.join(File.dirname(gemfile), app_config, "config") if gemfile end
.config_value(file, key) (private)
A config file that cannot be read or parsed leaves the setting
unconfigured rather than aborting the gem command that only wanted to
consult it. The rescue is deliberately broad: YAMLSerializer signals
a bad document with ::Psych::DisallowedClass, ::Psych::BadAlias and
::Psych::SyntaxError, which share no class this method could name, and a
reader that only ever returns a value or nil gains nothing from letting a
newly added one through.
# File 'lib/rubygems/bundler_settings.rb', line 124
def self.config_value(file, key) return unless file && File.file?(file) require_relative "yaml_serializer" config = Gem::YAMLSerializer.load File.read(file) # A config file whose top level is not a mapping has no settings in it, # and indexing it would read a substring or raise instead of saying so. config[key] if config.is_a?(Hash) rescue StandardError nil end
.env(name)
The value of Bundler setting name from the environment, or nil when the
variable is unset or empty.
.env_value(key) (private)
[ GitHub ]# File 'lib/rubygems/bundler_settings.rb', line 73
def self.env_value(key) value = ENV[key] value unless value.nil? || value.empty? end
.from_config_files(name)
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
.gemfile_path
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
.key_for(name) (private)
[ GitHub ]# File 'lib/rubygems/bundler_settings.rb', line 68
def self.key_for(name) "BUNDLE_#{name.to_s.gsub(".", "__").gsub("-", "___").upcase}" end
.user_config_file (private)
[ GitHub ]# File 'lib/rubygems/bundler_settings.rb', line 96
def self.user_config_file return if ignore_config? file = env_value("BUNDLE_CONFIG") || env_value("BUNDLE_USER_CONFIG") return file if file home = env_value("BUNDLE_USER_HOME") return File.join(home, "config") if home user_home = Gem.user_home File.join(user_home, ".bundle", "config") if user_home && !user_home.empty? end