Class: Bundler::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/mirror.rb,
lib/bundler/settings.rb

Defined Under Namespace

Classes: Mirror, MirrorConfig, Mirrors, TCPSocketProbe

Constant Summary

BOOL_KEYS =
%w(
  allow_offline_install
  auto_install
  cache_all
  cache_all_platforms
  disable_checksum_validation
  disable_exec_load
  disable_local_branch_check
  disable_shared_gems
  disable_version_check
  force_ruby_platform
  frozen
  gem.coc
  gem.mit
  ignore_messages
  major_deprecations
  no_install
  no_prune
  only_update_to_newer_versions
  plugins
  silence_root_warning
).freeze
NUMBER_KEYS =
%w(
  redirect
  retry
  ssl_verify_mode
  timeout
).freeze
DEFAULT_CONFIG =
{
  :redirect => 5,
  :retry => 3,
  :timeout => 10,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = nil) ⇒ Settings

Returns a new instance of Settings



47
48
49
50
51
52
53
# File 'lib/bundler/settings.rb', line 47

def initialize(root = nil)
  @root            = root
  @local_config    = load_config(local_config_file)
  @global_config   = load_config(global_config_file)
  @cli_flags_given = false
  @temporary       = {}
end

Instance Attribute Details

#cli_flags_givenObject

Returns the value of attribute cli_flags_given



45
46
47
# File 'lib/bundler/settings.rb', line 45

def cli_flags_given
  @cli_flags_given
end

Instance Method Details

#[](name) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/bundler/settings.rb', line 55

def [](name)
  key = key_for(name)
  value = @temporary.fetch(name) do
          @local_config.fetch(key) do
          ENV.fetch(key) do
          @global_config.fetch(key) do
          DEFAULT_CONFIG.fetch(name) do
            nil
          end end end end end

  if value.nil?
    nil
  elsif is_bool(name) || value == "false"
    to_bool(value)
  elsif is_num(name)
    value.to_i
  else
    value
  end
end

#[]=(key, value) ⇒ Object Also known as: set_local



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/bundler/settings.rb', line 76

def []=(key, value)
  if cli_flags_given
    command = if value.nil?
      "bundle config --delete #{key}"
    else
      "bundle config #{key} #{Array(value).join(":")}"
    end

    Bundler::SharedHelpers.major_deprecation \
      "flags passed to commands " \
      "will no longer be automatically remembered. Instead please set flags " \
      "you want remembered between commands using `bundle config " \
      "<setting name> <setting value>`, i.e. `#{command}`"
  end
  local_config_file || raise(GemfileNotFound, "Could not locate Gemfile")
  set_key(key, value, @local_config, local_config_file)
end

#allObject



114
115
116
117
118
119
120
121
122
# File 'lib/bundler/settings.rb', line 114

def all
  env_keys = ENV.keys.select {|k| k =~ /BUNDLE_.*/ }

  keys = @global_config.keys | @local_config.keys | env_keys

  keys.map do |key|
    key.sub(/^BUNDLE_/, "").gsub(/__/, ".").downcase
  end
end

#allow_sudo?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/bundler/settings.rb', line 207

def allow_sudo?
  !@local_config.key?(key_for(:path))
end

#app_cache_pathObject



215
216
217
218
219
220
221
# File 'lib/bundler/settings.rb', line 215

def app_cache_path
  @app_cache_path ||= begin
    path = self[:cache_path] || "vendor/cache"
    raise InvalidOption, "Cache path must be relative to the bundle path" if path.start_with?("/")
    path
  end
end

#credentials_for(uri) ⇒ Object



137
138
139
# File 'lib/bundler/settings.rb', line 137

def credentials_for(uri)
  self[uri.to_s] || self[uri.host]
end

#delete(key) ⇒ Object



106
107
108
# File 'lib/bundler/settings.rb', line 106

def delete(key)
  @local_config.delete(key_for(key))
end

#gem_mirrorsObject



141
142
143
144
145
146
# File 'lib/bundler/settings.rb', line 141

def gem_mirrors
  all.inject(Mirrors.new) do |mirrors, k|
    mirrors.parse(k, self[k]) if k =~ /^mirror\./
    mirrors
  end
end

#ignore_config?Boolean

Returns:

  • (Boolean)


211
212
213
# File 'lib/bundler/settings.rb', line 211

def ignore_config?
  ENV["BUNDLE_IGNORE_CONFIG"]
end

#local_overridesObject



124
125
126
127
128
129
130
# File 'lib/bundler/settings.rb', line 124

def local_overrides
  repos = {}
  all.each do |k|
    repos[$'] = self[k] if k =~ /^local\./
  end
  repos
end

#locations(key) ⇒ Object



148
149
150
151
152
153
154
155
156
# File 'lib/bundler/settings.rb', line 148

def locations(key)
  key = key_for(key)
  locations = {}
  locations[:local]  = @local_config[key] if @local_config.key?(key)
  locations[:env]    = ENV[key] if ENV[key]
  locations[:global] = @global_config[key] if @global_config.key?(key)
  locations[:default] = DEFAULT_CONFIG[key] if DEFAULT_CONFIG.key?(key)
  locations
end

#mirror_for(uri) ⇒ Object



132
133
134
135
# File 'lib/bundler/settings.rb', line 132

def mirror_for(uri)
  uri = URI(uri.to_s) unless uri.is_a?(URI)
  gem_mirrors.for(uri.to_s).uri
end

#pathObject

@local_config should be prioritized over ENV



195
196
197
198
199
200
201
202
203
204
205
# File 'lib/bundler/settings.rb', line 195

def path
  key  = key_for(:path)
  path = ENV[key] || @global_config[key]
  return path if path && !@local_config.key?(key)

  if path = self[:path]
    "#{path}/#{Bundler.ruby_scope}"
  else
    Bundler.rubygems.gem_dir
  end
end

#pretty_values_for(exposed_key) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/bundler/settings.rb', line 158

def pretty_values_for(exposed_key)
  key = key_for(exposed_key)

  locations = []
  if @local_config.key?(key)
    locations << "Set for your local app (#{local_config_file}): #{@local_config[key].inspect}"
  end

  if value = ENV[key]
    locations << "Set via #{key}: #{value.inspect}"
  end

  if @global_config.key?(key)
    locations << "Set for the current user (#{global_config_file}): #{@global_config[key].inspect}"
  end

  return ["You have not configured a value for `#{exposed_key}`"] if locations.empty?
  locations
end

#set_global(key, value) ⇒ Object



110
111
112
# File 'lib/bundler/settings.rb', line 110

def set_global(key, value)
  set_key(key, value, @global_config, global_config_file)
end

#temporary(update) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/bundler/settings.rb', line 95

def temporary(update)
  existing = Hash[update.map {|k, _| [k, @temporary[k]] }]
  @temporary.update(update)
  return unless block_given?
  begin
    yield
  ensure
    existing.each {|k, v| v.nil? ? @temporary.delete(k) : @temporary[k] = v }
  end
end

#withObject



190
191
192
# File 'lib/bundler/settings.rb', line 190

def with
  get_array(:with)
end

#with=(array) ⇒ Object



182
183
184
# File 'lib/bundler/settings.rb', line 182

def with=(array)
  set_array(:with, array)
end

#withoutObject



186
187
188
# File 'lib/bundler/settings.rb', line 186

def without
  get_array(:without)
end

#without=(array) ⇒ Object



178
179
180
# File 'lib/bundler/settings.rb', line 178

def without=(array)
  set_array(:without, array)
end