diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-04-17 19:57:36 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-04-19 06:56:20 +0000 |
commit | 7b959f628801d9f411a2dcc231c25a06e9d6234f (patch) | |
tree | 7fc585e4387041edff2c87dd443f3ad02295f072 /lib/rubygems/config_file.rb | |
parent | 30b3290f266609d502791ec5d2edb4885d89d462 (diff) |
[rubygems/rubygems] Move all changes only in RubyGems
https://github.com/rubygems/rubygems/commit/d842e2092f
Diffstat (limited to 'lib/rubygems/config_file.rb')
-rw-r--r-- | lib/rubygems/config_file.rb | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 2191a81184..b5c4b4dcf4 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -320,6 +320,10 @@ if you believe they were disclosed to a third party. config = load_file(credentials_path).merge(host => api_key) + config.transform_keys! do |k| + k.is_a?(Symbol) ? ":#{k}" : k + end + dirname = File.dirname credentials_path require "fileutils" FileUtils.mkdir_p(dirname) @@ -351,10 +355,36 @@ if you believe they were disclosed to a third party. return {} unless filename && !filename.empty? && File.exist?(filename) begin - content = Bundler::YAMLSerializer.load(File.read(filename), is_rubygems: true) + content = Bundler::YAMLSerializer.load(File.read(filename)) if content.is_a? Hash + content.transform_keys! do |k| + if k.match?(/\A:(.*)\Z/) + k[1..-1].to_sym + elsif k.match?(/__/) + if k.is_a?(Symbol) + k.to_s.gsub(/__/,".").to_sym + else + k.dup.gsub(/__/,".") + end + else + k + end + end + content.transform_values! do |v| - if (v.is_a?(Hash) || v.is_a?(String)) && v.empty? + if v.is_a?(String) + if v.match?(/\A:(.*)\Z/) + v[1..-1].to_sym + elsif v.match?(/\A[+-]?\d+\Z/) + v.to_i + elsif v.match?(/\Atrue|false\Z/) + v == "true" + elsif v.empty? + nil + else + v + end + elsif v.is_a?(Hash) && v.empty? nil else v @@ -494,6 +524,10 @@ if you believe they were disclosed to a third party. yaml_hash[key.to_s] = value end + yaml_hash.transform_keys! do |k| + k.is_a?(Symbol) ? ":#{k}" : k + end + require "bundler/yaml_serializer" Bundler::YAMLSerializer.dump(yaml_hash) end |