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
25 def invoke_with_location(lookup_invocation, location, root_key, merge)
26   if location.nil?
27     value = lookup_key(root_key, lookup_invocation, nil, merge)
28     lookup_invocation.report_found(root_key, value)
29   else
30     lookup_invocation.with(:location, location) do
31       value = lookup_key(root_key, lookup_invocation, location, merge)
32       lookup_invocation.report_found(root_key, value)
33     end
34   end
35 end
label() click to toggle source
   # File lib/puppet/pops/lookup/lookup_key_function_provider.rb
37 def label
38   'Lookup Key'
39 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
16 def unchecked_key_lookup(key, lookup_invocation, merge)
17   root_key = key.root_key
18   lookup_invocation.with(:data_provider, self) do
19     MergeStrategy.strategy(merge).lookup(locations, lookup_invocation) do |location|
20       invoke_with_location(lookup_invocation, location, root_key, merge)
21     end
22   end
23 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
43 def lookup_key(key, lookup_invocation, location, merge)
44   unless location.nil? || location.exist?
45     lookup_invocation.report_location_not_found
46     throw :no_such_key
47   end
48   ctx = function_context(lookup_invocation, location)
49   ctx.data_hash ||= {}
50   catch(:no_such_key) do
51     hash = ctx.data_hash
52     unless hash.include?(key)
53       hash[key] = validate_data_value(ctx.function.call(lookup_invocation.scope, key, options(location), Context.new(ctx, lookup_invocation))) do
54         msg = "Value for key '#{key}', returned from #{full_name}"
55         location.nil? ? msg : "#{msg}, when using location '#{location}',"
56       end
57     end
58     return hash[key]
59   end
60   lookup_invocation.report_not_found(key)
61   throw :no_such_key
62 end