class Puppet::Pops::Lookup::LookupKeyFunctionProvider

@api private

Constants

TAG

Public Instance Methods

invoke_with_location(lookup_invocation, location, root_key, merge) click to toggle source
   # File lib/puppet/pops/lookup/lookup_key_function_provider.rb
26 def invoke_with_location(lookup_invocation, location, root_key, merge)
27   if location.nil?
28     value = lookup_key(root_key, lookup_invocation, nil, merge)
29     lookup_invocation.report_found(root_key, value)
30   else
31     lookup_invocation.with(:location, location) do
32       value = lookup_key(root_key, lookup_invocation, location, merge)
33       lookup_invocation.report_found(root_key, value)
34     end
35   end
36 end
label() click to toggle source
   # File lib/puppet/pops/lookup/lookup_key_function_provider.rb
38 def label
39   'Lookup Key'
40 end
unchecked_key_lookup(key, lookup_invocation, merge) click to toggle source

Performs a lookup with the assumption that a recursive check has been made.

@param key [LookupKey] The key to lookup @param lookup_invocation [Invocation] The current lookup invocation @param merge [MergeStrategy,String,Hash{String => Object},nil] Merge strategy, merge strategy name, strategy and options hash, or nil (implies “first found”) @return [Object] the found object @throw :no_such_key when the object is not found

   # File lib/puppet/pops/lookup/lookup_key_function_provider.rb
17 def unchecked_key_lookup(key, lookup_invocation, merge)
18   root_key = key.root_key
19   lookup_invocation.with(:data_provider, self) do
20     MergeStrategy.strategy(merge).lookup(locations, lookup_invocation) do |location|
21       invoke_with_location(lookup_invocation, location, root_key, merge)
22     end
23   end
24 end

Private Instance Methods

lookup_key(key, lookup_invocation, location, merge) click to toggle source
   # File lib/puppet/pops/lookup/lookup_key_function_provider.rb
44 def lookup_key(key, lookup_invocation, location, merge)
45   unless location.nil? || location.exist?
46     lookup_invocation.report_location_not_found
47     throw :no_such_key
48   end
49   ctx = function_context(lookup_invocation, location)
50   ctx.data_hash ||= {}
51   catch(:no_such_key) do
52     hash = ctx.data_hash
53     unless hash.include?(key)
54       hash[key] = validate_data_value(ctx.function.call(lookup_invocation.scope, key, options(location), Context.new(ctx, lookup_invocation))) do
55         msg = "Value for key '#{key}', returned from #{full_name}"
56         location.nil? ? msg : "#{msg}, when using location '#{location}',"
57       end
58     end
59     return hash[key]
60   end
61   lookup_invocation.report_not_found(key)
62   throw :no_such_key
63 end