[rubygems/rubygems] Wrap self.convert_rubygems_config_hash from Bundler::YAMLSerializer.load

https://github.com/rubygems/rubygems/commit/080880ac23
This commit is contained in:
Hiroshi SHIBATA 2023-04-17 20:24:13 +09:00 коммит произвёл git
Родитель 7b959f6288
Коммит cdc2e3de10
3 изменённых файлов: 44 добавлений и 35 удалений

Просмотреть файл

@ -357,39 +357,7 @@ if you believe they were disclosed to a third party.
begin
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?(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
end
end
content = self.class.convert_rubygems_config_hash(content)
else
warn "Failed to load #{filename} because it doesn't contain valid YAML hash"
return {}
@ -564,6 +532,44 @@ if you believe they were disclosed to a third party.
attr_reader :hash
protected :hash
def self.convert_rubygems_config_hash(content)
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?(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
end
end
content
end
private
def set_config_file_name(args)

Просмотреть файл

@ -334,7 +334,8 @@ module Gem::GemcutterUtilities
require "bundler/yaml_serializer"
with_response response do |resp|
Bundler::YAMLSerializer.load clean_text(resp.body)
profile = Bundler::YAMLSerializer.load clean_text(resp.body)
Gem::ConfigFile.convert_rubygems_config_hash profile
end
end

Просмотреть файл

@ -680,7 +680,9 @@ class Gem::TestCase < Test::Unit::TestCase
def load_yaml_file(file)
require "bundler/yaml_serializer"
Bundler::YAMLSerializer.load(File.read(file))
require "rubygems/config_file"
yaml = Bundler::YAMLSerializer.load(File.read(file))
Gem::ConfigFile.convert_rubygems_config_hash(yaml)
end
def all_spec_names