[rubygems/rubygems] Move all changes only in RubyGems

https://github.com/rubygems/rubygems/commit/d842e2092f
This commit is contained in:
Hiroshi SHIBATA 2023-04-17 19:57:36 +09:00 коммит произвёл git
Родитель 30b3290f26
Коммит 7b959f6288
4 изменённых файлов: 43 добавлений и 26 удалений

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

@ -461,7 +461,7 @@ module Bundler
new_k = k.gsub("-", "___")
end
config[new_k] = v.to_s
config[new_k] = v
config
end
end

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

@ -13,11 +13,7 @@ module Bundler
def dump_hash(hash)
yaml = String.new("\n")
hash.each do |k, v|
if k.is_a?(Symbol)
yaml << ":#{k}:"
else
yaml << k << ":"
end
yaml << k << ":"
if v.is_a?(Hash)
yaml << dump_hash(v).gsub(/^(?!$)/, " ") # indent all non-empty lines
elsif v.is_a?(Array) # Expected to be array of strings
@ -50,7 +46,7 @@ module Bundler
$
/xo.freeze
def load(str, is_rubygems: false)
def load(str)
res = {}
stack = [res]
last_hash = nil
@ -58,8 +54,7 @@ module Bundler
str.split(/\r?\n/).each do |line|
if match = HASH_REGEX.match(line)
indent, key, quote, val = match.captures
key = convert_to_backward_compatible_key(key) unless is_rubygems
key = key[1..-1].to_sym if key.start_with?(":")
key = convert_to_backward_compatible_key(key)
depth = indent.scan(/ /).length
if quote.empty? && val.empty?
new_hash = {}
@ -68,30 +63,18 @@ module Bundler
last_empty_key = key
last_hash = stack[depth]
else
stack[depth][key] = convert_to_ruby_value(val)
stack[depth][key] = val
end
elsif match = ARRAY_REGEX.match(line)
_, val = match.captures
last_hash[last_empty_key] = [] unless last_hash[last_empty_key].is_a?(Array)
last_hash[last_empty_key].push(convert_to_ruby_value(val))
last_hash[last_empty_key].push(val)
end
end
res
end
def convert_to_ruby_value(val)
if val.match?(/\A:(.*)\Z/)
val[1..-1].to_sym
elsif val.match?(/\A[+-]?\d+\Z/)
val.to_i
elsif val.match?(/\Atrue|false\Z/)
val == "true"
else
val
end
end
# for settings' keys
def convert_to_backward_compatible_key(key)
key = "#{key}/" if key =~ /https?:/i && key !~ %r{/\Z}

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

@ -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

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

@ -680,7 +680,7 @@ class Gem::TestCase < Test::Unit::TestCase
def load_yaml_file(file)
require "bundler/yaml_serializer"
Bundler::YAMLSerializer.load(File.read(file), is_rubygems: true)
Bundler::YAMLSerializer.load(File.read(file))
end
def all_spec_names