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/bundler/yaml_serializer.rb | |
parent | 30b3290f266609d502791ec5d2edb4885d89d462 (diff) |
[rubygems/rubygems] Move all changes only in RubyGems
https://github.com/rubygems/rubygems/commit/d842e2092f
Diffstat (limited to 'lib/bundler/yaml_serializer.rb')
-rw-r--r-- | lib/bundler/yaml_serializer.rb | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 23dce9440b..d5ecbd4aef 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -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} |