def lookup(key, scope, order_override, resolution_type)
answer = nil
Hiera.debug("Looking up #{key} in YAML backend")
Backend.datasources(scope, order_override) do |source|
Hiera.debug("Looking for data source #{source}")
yamlfile = Backend.datafile(:yaml, scope, source, "yaml") || next
if @data[yamlfile]
@data[yamlfile] = YAML.load_file(yamlfile) if stale?(yamlfile)
else
@data[yamlfile] = YAML.load_file(yamlfile)
end
next if ! @data[yamlfile]
next if @data[yamlfile].empty?
next unless @data[yamlfile].include?(key)
Hiera.debug("Found #{key} in #{source}")
new_answer = Backend.parse_answer(@data[yamlfile][key], scope)
case resolution_type
when :array
raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
answer ||= []
answer << new_answer
when :hash
raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
answer ||= {}
answer = new_answer.merge answer
else
answer = new_answer
break
end
end
return answer
end