summaryrefslogtreecommitdiff
path: root/lib/bundler/yaml_serializer.rb
diff options
context:
space:
mode:
authorAsutosh Palai <asupalai@gmail.com>2016-06-28 14:59:41 +0530
committerAsutosh Palai <asupalai@gmail.com>2016-07-03 09:41:58 +0530
commit89c7180ee7c5b1a1ab254e7e142a473ea51d1de3 (patch)
tree4a3a125d91493a9b0256aa12070767ece540d8fd /lib/bundler/yaml_serializer.rb
parent65c967e5529efc3e249aa63edd87e747f6724001 (diff)
downloadbundler-89c7180ee7c5b1a1ab254e7e142a473ea51d1de3.tar.gz
[Serializer]Array parser implemented
Diffstat (limited to 'lib/bundler/yaml_serializer.rb')
-rw-r--r--lib/bundler/yaml_serializer.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb
index 43c24cf6b5..dede8fd5fd 100644
--- a/lib/bundler/yaml_serializer.rb
+++ b/lib/bundler/yaml_serializer.rb
@@ -27,11 +27,10 @@ module Bundler
ARRAY_REGEX = /
^
- ([ ]*) # indentations
- (?:-[ ]) # '- ' before array items
+ (?:[ ]*-[ ]) # '- ' before array items
(['"]?) # optional opening quote
(.*) # value
- \2 # matching closing quote
+ \1 # matching closing quote
$
/xo
@@ -51,18 +50,27 @@ module Bundler
def load(str)
res = {}
stack = [res]
+ last_hash = nil
+ last_empty_key = nil
str.split("\n").each do |line|
- if line =~ HASH_REGEX
- indent, key, _, val = HASH_REGEX.match(line).captures
+ if match = HASH_REGEX.match(line)
+ indent, key, _, val = match.captures
key = convert_to_backward_compatible_key(key)
depth = indent.scan(/ /).length
if val.empty?
new_hash = {}
stack[depth][key] = new_hash
stack[depth + 1] = new_hash
+ last_empty_key = key
+ last_hash = stack[depth]
else
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(val)
end
end
res