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
  disable_exec_load
  disable_local_branch_check
  disable_shared_gems
  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



40
41
42
43
44
45
# File 'lib/bundler/settings.rb', line 40

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

Instance Attribute Details

#cli_flags_givenObject

Returns the value of attribute cli_flags_given



38
39
40
# File 'lib/bundler/settings.rb', line 38

def cli_flags_given
  @cli_flags_given
end

Instance Method Details

#[](name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bundler/settings.rb', line 47

def [](name)
  key = key_for(name)
  value = (@local_config[key] || ENV[key] || @global_config[key] || DEFAULT_CONFIG[name])

  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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bundler/settings.rb', line 62

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



90
91
92
93
94
95
96
97
98
# File 'lib/bundler/settings.rb', line 90

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)


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

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

#app_cache_pathObject



191
192
193
194
195
196
197
# File 'lib/bundler/settings.rb', line 191

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



113
114
115
# File 'lib/bundler/settings.rb', line 113

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

#delete(key) ⇒ Object



82
83
84
# File 'lib/bundler/settings.rb', line 82

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

#gem_mirrorsObject



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

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)


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

def ignore_config?
  ENV["BUNDLE_IGNORE_CONFIG"]
end

#local_overridesObject



100
101
102
103
104
105
106
# File 'lib/bundler/settings.rb', line 100

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

#locations(key) ⇒ Object



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

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



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

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



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/bundler/settings.rb', line 171

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



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/bundler/settings.rb', line 134

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



86
87
88
# File 'lib/bundler/settings.rb', line 86

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

#withObject



166
167
168
# File 'lib/bundler/settings.rb', line 166

def with
  get_array(:with)
end

#with=(array) ⇒ Object



158
159
160
# File 'lib/bundler/settings.rb', line 158

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

#withoutObject



162
163
164
# File 'lib/bundler/settings.rb', line 162

def without
  get_array(:without)
end

#without=(array) ⇒ Object



154
155
156
# File 'lib/bundler/settings.rb', line 154

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