class Stibium::Bundled::Bundle::Config
Describe bundler configuration settings.
Bundler loads configuration settings in this order:
-
Local config (“.bundle/config“ or “$BUNDLE_APP_CONFIG/config“)
-
Environment variables (“ENV“)
-
Global config (“~/.bundle/config“)
-
Bundler default config - PARTIAL support is implemented in “Config.defaults“
@note Executing bundle with the “BUNDLE_IGNORE_CONFIG“ environment set will cause it to ignore all configuration.
@see bundler.io/v2.2/bundle_config.html @see evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development @see .load @see .read @see .env @see .defaults
Attributes
@return [Pathname]
@return [Hash{String => Object}]
Public Class Methods
@param basedir [String, Pathname] @param env [Hash{String => String}]
# File lib/stibium/bundled/bundle/config.rb, line 38 def initialize(basedir, env: ENV.to_h) super().tap do @basedir = Pathname.new(basedir).freeze @env = self.class.__send__(:env, source: env).freeze self.class.__send__(:call, self.resolve_file, env: env).each { |k, v| self[k.freeze] = v.freeze } end.freeze end
Protected Class Methods
Load config.
@param file [Pathname] @param env [Hash{String => String}]
@api private @see bundler.io/v2.2/bundle_config.html
@return [Hash{String => Object}]
# File lib/stibium/bundled/bundle/config.rb, line 98 def call(file, env: ENV.to_h) # @formatter:off self.defaults # 4. Bundler default config .merge(self.global_config(env: env)) # 3. Global config .merge(self.env(source: env)) # 2. Environmental variables .merge(self.read(file, env: env)) # 1. Local config .sort.map { |k, v| [k.freeze, v.freeze] }.to_h.freeze # @formatter:on end
Default config values (as seen from an empty environment).
“`shell rm -rfv ~/.bundle/config .bundle/config env -i $(which bundle) install –standalone cat .bundle/config “`
@see Stibium::Bundled::Bundle#bundler_setup
# File lib/stibium/bundled/bundle/config.rb, line 80 def defaults { 'BUNDLE_APP_CONFIG' => '.bundle', 'BUNDLE_PATH' => 'bundle', } end
Get bundler related environment variables (“/^BUNDLE_.+/“)
@param source [Hash{String => String}]
@api private
@return [Hash{String => Object}]
# File lib/stibium/bundled/bundle/config.rb, line 130 def env(source: ENV.to_h) source.dup.keep_if { |k, _| /^BUNDLE_.+/ =~ k } .transform_keys(&:freeze) .transform_values { |v| (v.is_a?(String) ? YAML.safe_load(v) : v).freeze } .sort.to_h end
Get global config.
@api private
@param env [Hash{String => String}]
@return [Hash{String => Object}]
# File lib/stibium/bundled/bundle/config.rb, line 115 def global_config(env: ENV.to_h) env['HOME'].yield_self do |home_path| return {} if home_path.nil? Pathname.new(home_path).expand_path.join('.bundle/config').yield_self { |file| self.read(file, env: env) } end end
Read given config file.
@api private
@param file [Pathname] @param env [Hash{String => String}]
@return [Hash{String => Object}]
# File lib/stibium/bundled/bundle/config.rb, line 145 def read(file, env: ENV.to_h) Reader.new(env: env).read(file) end
Protected Instance Methods
Resolve path to local config (depending on “BUNDLE_APP_CONFIG“ value).
@return [Pathname]
# File lib/stibium/bundled/bundle/config.rb, line 58 def resolve_file begin 'BUNDLE_APP_CONFIG'.yield_self do |k| self.env.fetch(k) { self.class.defaults.fetch(k) } end end.yield_self do |s| Pathname.new(s) end.yield_self do |path| (path.absolute? ? path : basedir.join(path)).join('config') end end