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 13 def self.trusted_return_type 14 @trusted_return_type ||= Types::PHashType.new(DataProvider.key_type, DataProvider.value_type) 15 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 24 def unchecked_key_lookup(key, lookup_invocation, merge) 25 root_key = key.root_key 26 lookup_invocation.with(:data_provider, self) do 27 MergeStrategy.strategy(merge).lookup(locations, lookup_invocation) do |location| 28 invoke_with_location(lookup_invocation, location, root_key) 29 end 30 end 31 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 76 def call_data_hash_function(ctx, lookup_invocation, location) 77 ctx.function.call(lookup_invocation.scope, options(location), Context.new(ctx, lookup_invocation)) 78 end
data_hash(lookup_invocation, location)
click to toggle source
# File lib/puppet/pops/lookup/data_hash_function_provider.rb 68 def data_hash(lookup_invocation, location) 69 ctx = function_context(lookup_invocation, location) 70 ctx.data_hash ||= parent_data_provider.validate_data_hash(call_data_hash_function(ctx, lookup_invocation, location)) do 71 msg = "Value returned from #{full_name}" 72 location.nil? ? msg : "#{msg}, when using location '#{location}'," 73 end 74 end
data_value(lookup_invocation, location, root_key)
click to toggle source
# File lib/puppet/pops/lookup/data_hash_function_provider.rb 54 def data_value(lookup_invocation, location, root_key) 55 hash = data_hash(lookup_invocation, location) 56 value = hash[root_key] 57 if value.nil? && !hash.include?(root_key) 58 lookup_invocation.report_not_found(root_key) 59 throw :no_such_key 60 end 61 value = validate_data_value(value) do 62 msg = "Value for key '#{root_key}', in hash returned from #{full_name}" 63 location.nil? ? msg : "#{msg}, when using location '#{location}'," 64 end 65 interpolate(value, lookup_invocation, true) 66 end
invoke_with_location(lookup_invocation, location, root_key)
click to toggle source
# File lib/puppet/pops/lookup/data_hash_function_provider.rb 35 def invoke_with_location(lookup_invocation, location, root_key) 36 if location.nil? 37 lookup_key(lookup_invocation, nil, root_key) 38 else 39 lookup_invocation.with(:location, location) do 40 if location.exist? 41 lookup_key(lookup_invocation, location, root_key) 42 else 43 lookup_invocation.report_location_not_found 44 throw :no_such_key 45 end 46 end 47 end 48 end
lookup_key(lookup_invocation, location, root_key)
click to toggle source
# File lib/puppet/pops/lookup/data_hash_function_provider.rb 50 def lookup_key(lookup_invocation, location, root_key) 51 lookup_invocation.report_found(root_key, data_value(lookup_invocation, location, root_key)) 52 end