def lookup(key, scope, order_override, resolution_type)
debug("Lookup called for key #{key}")
answer = nil
Backend.datasources(scope, order_override) do |source|
eyaml_file = Backend.datafile(:eyaml, scope, source, @extension) || next
debug("Processing datasource: #{eyaml_file}")
data = YAML.load(File.read( eyaml_file ))
next if data.nil? or data.empty?
debug ("Data contains valid YAML")
next unless data.include?(key)
debug ("Key #{key} found in YAML document")
parsed_answer = parse_answer(key, data[key], scope)
begin
case resolution_type
when :array
debug("Appending answer array")
raise Exception, "Hiera type mismatch: expected Array and got #{parsed_answer.class}" unless parsed_answer.kind_of? Array or parsed_answer.kind_of? String
answer ||= []
answer << parsed_answer
when :hash
debug("Merging answer hash")
raise Exception, "Hiera type mismatch: expected Hash and got #{parsed_answer.class}" unless parsed_answer.kind_of? Hash
answer ||= {}
answer = Backend.merge_answer(parsed_answer,answer)
else
debug("Assigning answer variable")
answer = parsed_answer
break
end
rescue NoMethodError
raise Exception, "Resolution type is #{resolution_type} but parsed_answer is a #{parsed_answer.class}"
end
end
answer
end