diff options
author | The Bundler Bot <bot@bundler.io> | 2017-06-23 06:04:42 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-06-23 06:04:42 +0000 |
commit | 1018408d64a7b42f4c901b22af7ce3f9a3558120 (patch) | |
tree | f9383a909fa9bf185c052c33e1876f5cdf70b935 | |
parent | 1102ec1a06d5971fc3c870b1ed50de8f826c36e4 (diff) | |
parent | 2f7fe6af5b0e45c00717810008f6c91eeb241775 (diff) | |
download | bundler-1018408d64a7b42f4c901b22af7ce3f9a3558120.tar.gz |
Auto merge of #5809 - bundler:seg-config-converted-value, r=indirect
[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`
-rw-r--r-- | lib/bundler/settings.rb | 28 | ||||
-rw-r--r-- | spec/bundler/settings_spec.rb | 10 |
2 files changed, 26 insertions, 12 deletions
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 77f01774a2..078c517919 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -68,15 +68,7 @@ module Bundler 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) @@ -168,15 +160,15 @@ module Bundler 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? @@ -285,6 +277,18 @@ module Bundler 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"]) diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb index 1c66cd73af..1acd2a97b3 100644 --- a/spec/bundler/settings_spec.rb +++ b/spec/bundler/settings_spec.rb @@ -150,6 +150,16 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow 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/") } |