summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-06-22 12:58:13 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-06-22 12:58:13 -0500
commit2f7fe6af5b0e45c00717810008f6c91eeb241775 (patch)
tree9ff8fc9f539bd108ae207f446f9722c7b5bfb7fc
parent67ff76af19e6d033d26e63ff2f064754316fee38 (diff)
downloadbundler-seg-config-converted-value.tar.gz
[Settings] Print pretty values for settings as their converted values, rather than stringsseg-config-converted-value
-rw-r--r--lib/bundler/settings.rb28
-rw-r--r--spec/bundler/settings_spec.rb10
2 files changed, 26 insertions, 12 deletions
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index e0eb660a8a..f51e995d50 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -67,15 +67,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)
@@ -167,15 +159,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?
@@ -284,6 +276,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/") }