class Puppet::Pops::Lookup::DataDigFunctionProvider

@api private

Constants

TAG

Public Instance Methods

invoke_with_location(lookup_invocation, location, key, merge) click to toggle source
   # File lib/puppet/pops/lookup/data_dig_function_provider.rb
24 def invoke_with_location(lookup_invocation, location, key, merge)
25   if location.nil?
26     key.undig(lookup_invocation.report_found(key, validated_data_dig(key, lookup_invocation, nil, merge)))
27   else
28     lookup_invocation.with(:location, location) do
29       key.undig(lookup_invocation.report_found(key, validated_data_dig(key, lookup_invocation, location, merge)))
30     end
31   end
32 end
label() click to toggle source
   # File lib/puppet/pops/lookup/data_dig_function_provider.rb
34 def label
35   'Data Dig'
36 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/data_dig_function_provider.rb
16 def unchecked_key_lookup(key, lookup_invocation, merge)
17   lookup_invocation.with(:data_provider, self) do
18     MergeStrategy.strategy(merge).lookup(locations, lookup_invocation) do |location|
19       invoke_with_location(lookup_invocation, location, key, merge)
20     end
21   end
22 end
validated_data_dig(key, lookup_invocation, location, merge) click to toggle source
   # File lib/puppet/pops/lookup/data_dig_function_provider.rb
38 def validated_data_dig(key, lookup_invocation, location, merge)
39   validate_data_value(data_dig(key, lookup_invocation, location, merge)) do
40     msg = "Value for key '#{key}', returned from #{full_name}"
41     location.nil? ? msg : "#{msg}, when using location '#{location}',"
42   end
43 end

Private Instance Methods

data_dig(key, lookup_invocation, location, merge) click to toggle source
   # File lib/puppet/pops/lookup/data_dig_function_provider.rb
47 def data_dig(key, lookup_invocation, location, merge)
48   unless location.nil? || location.exist?
49     lookup_invocation.report_location_not_found
50     throw :no_such_key
51   end
52   ctx = function_context(lookup_invocation, location)
53   ctx.data_hash ||= {}
54   catch(:no_such_key) do
55     hash = ctx.data_hash
56     hash[key] = ctx.function.call(lookup_invocation.scope, key.to_a, options(location), Context.new(ctx, lookup_invocation)) unless hash.include?(key)
57     return hash[key]
58   end
59   lookup_invocation.report_not_found(key)
60   throw :no_such_key
61 end