class Puppet::Pops::Lookup::DataHashFunctionProvider

@api private

Constants

TAG

Public Class Methods

trusted_return_type() click to toggle source
   # File lib/puppet/pops/lookup/data_hash_function_provider.rb
14 def self.trusted_return_type
15   @trusted_return_type ||= Types::PHashType.new(DataProvider.key_type, DataProvider.value_type)
16 end

Public Instance Methods

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_hash_function_provider.rb
25 def unchecked_key_lookup(key, lookup_invocation, merge)
26   root_key = key.root_key
27   lookup_invocation.with(:data_provider, self) do
28     MergeStrategy.strategy(merge).lookup(locations, lookup_invocation) do |location|
29       invoke_with_location(lookup_invocation, location, root_key)
30     end
31   end
32 end

Private Instance Methods

call_data_hash_function(ctx, lookup_invocation, location) click to toggle source
   # File lib/puppet/pops/lookup/data_hash_function_provider.rb
77 def call_data_hash_function(ctx, lookup_invocation, location)
78   ctx.function.call(lookup_invocation.scope, options(location), Context.new(ctx, lookup_invocation))
79 end
data_hash(lookup_invocation, location) click to toggle source
   # File lib/puppet/pops/lookup/data_hash_function_provider.rb
69 def data_hash(lookup_invocation, location)
70   ctx = function_context(lookup_invocation, location)
71   ctx.data_hash ||= parent_data_provider.validate_data_hash(call_data_hash_function(ctx, lookup_invocation, location)) do
72     msg = "Value returned from #{full_name}"
73     location.nil? ? msg : "#{msg}, when using location '#{location}',"
74   end
75 end
data_value(lookup_invocation, location, root_key) click to toggle source
   # File lib/puppet/pops/lookup/data_hash_function_provider.rb
55 def data_value(lookup_invocation, location, root_key)
56   hash = data_hash(lookup_invocation, location)
57   value = hash[root_key]
58   if value.nil? && !hash.include?(root_key)
59     lookup_invocation.report_not_found(root_key)
60     throw :no_such_key
61   end
62   value = validate_data_value(value) do
63     msg = "Value for key '#{root_key}', in hash returned from #{full_name}"
64     location.nil? ? msg : "#{msg}, when using location '#{location}',"
65   end
66   interpolate(value, lookup_invocation, true)
67 end
invoke_with_location(lookup_invocation, location, root_key) click to toggle source
   # File lib/puppet/pops/lookup/data_hash_function_provider.rb
36 def invoke_with_location(lookup_invocation, location, root_key)
37   if location.nil?
38     lookup_key(lookup_invocation, nil, root_key)
39   else
40     lookup_invocation.with(:location, location) do
41       if location.exist?
42         lookup_key(lookup_invocation, location, root_key)
43       else
44         lookup_invocation.report_location_not_found
45         throw :no_such_key
46       end
47     end
48   end
49 end
lookup_key(lookup_invocation, location, root_key) click to toggle source
   # File lib/puppet/pops/lookup/data_hash_function_provider.rb
51 def lookup_key(lookup_invocation, location, root_key)
52   lookup_invocation.report_found(root_key, data_value(lookup_invocation, location, root_key))
53 end