Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5809 - bundler:seg-config-converted-value, r=indirect
Browse files Browse the repository at this point in the history
[Settings] Print pretty values for settings as their converted values, rather than strings

### What was the end-user problem that led to this PR?

The problem was `bundle config` would print bool keys as strings (i.e. `true` was printed as `"true"`)

### Was was your diagnosis of the problem?

My diagnosis was we needed to convert the values before formatting them

### What is your fix for the problem, implemented in this PR?

My fix extracts the conversion method, and calls it in `pretty_values_for`
  • Loading branch information
bundlerbot committed Jun 23, 2017
2 parents 1102ec1 + 2f7fe6a commit 1018408
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/bundler/settings.rb
Expand Up @@ -68,15 +68,7 @@ def [](name)
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
converted_value(value, name)
end

def []=(key, value)
Expand Down Expand Up @@ -168,15 +160,15 @@ def pretty_values_for(exposed_key)

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

if value = ENV[key]
locations << "Set via #{key}: #{value.inspect}"
locations << "Set via #{key}: #{converted_value(value, exposed_key).inspect}"
end

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

return ["You have not configured a value for `#{exposed_key}`"] if locations.empty?
Expand Down Expand Up @@ -285,6 +277,18 @@ def set_key(key, value, hash, file)
value
end

def converted_value(value, key)
if value.nil?
nil
elsif is_bool(key) || value == "false"
to_bool(value)
elsif is_num(key)
value.to_i
else
value
end
end

def global_config_file
if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty?
Pathname.new(ENV["BUNDLE_CONFIG"])
Expand Down
10 changes: 10 additions & 0 deletions spec/bundler/settings_spec.rb
Expand Up @@ -150,6 +150,16 @@
end
end

describe "#pretty_values_for" do
it "prints the converted value rather than the raw string" do
bool_key = described_class::BOOL_KEYS.first
settings[bool_key] = false
expect(subject.pretty_values_for(bool_key)).to eq [
"Set for your local app (#{bundled_app("config")}): false",
]
end
end

describe "#mirror_for" do
let(:uri) { URI("https://rubygems.org/") }

Expand Down

0 comments on commit 1018408

Please sign in to comment.