method
load
v2_6_3 -
Show latest stable
- Class:
Bundler::YAMLSerializer
load(str)public
No documentation available.
# File lib/bundler/yaml_serializer.rb, line 50
def load(str)
res = {}
stack = [res]
last_hash = nil
last_empty_key = nil
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)
depth = indent.scan(/ /).length
if quote.empty? && 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
end