diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-06-09 13:47:02 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-06-09 13:47:16 +0530 |
commit | 8e6aab8395d0a6855886cbda8833a7f01f980298 (patch) | |
tree | dd88ee577f2b31484147008398f61d68edbe32f3 /lib/bundler/yaml_serializer.rb | |
parent | 3ddce71274da2ec529685635d90cc7a208b840c9 (diff) | |
download | bundler-8e6aab8395d0a6855886cbda8833a7f01f980298.tar.gz |
Made yaml_serializer compatible for use with settings
Diffstat (limited to 'lib/bundler/yaml_serializer.rb')
-rw-r--r-- | lib/bundler/yaml_serializer.rb | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index e64fe623c8..327baa4ee7 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -23,10 +23,24 @@ module Bundler yaml end + SCAN_REGEX = / + ^ + ([ ]*) # indentations + (.*) # key + (?::(?=\s)) # : (without the lookahead the #key includes this when : is present in value) + [ ]? + (?: !\s)? # optional exclamation mark found with ruby 1.9.3 + (['"]?) # optional opening quote + (.*) # value + \3 # matching closing quote + $ + /xo + def load(str) res = {} stack = [res] - str.scan(/^( *)(.*):\s?(["']?)([^"'\n]*)\3\n/).each do |(indent, key, _, val)| + str.scan(SCAN_REGEX).each do |(indent, key, _, val)| + key = convert_to_backward_compatible_key(key) depth = indent.scan(/ /).length if val.empty? new_hash = {} @@ -39,8 +53,15 @@ module Bundler res end + # for settings' keys + def convert_to_backward_compatible_key(key) + key = "#{key}/" if key =~ /https?:/i && key !~ %r{/\Z} + key = key.gsub(".", "__") if key.include?(".") + key + end + class << self - private :dump_hash + private :dump_hash, :convert_to_backward_compatible_key end end end |