class Puppet::Pops::Lookup::FunctionProvider
@api private
Attributes
function_name[R]
locations[R]
parent_data_provider[R]
Public Class Methods
new(name, parent_data_provider, function_name, options, locations)
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 23 def initialize(name, parent_data_provider, function_name, options, locations) 24 @name = name 25 @parent_data_provider = parent_data_provider 26 @function_name = function_name 27 @options = options 28 @locations = locations || [nil] 29 @contexts = {} 30 end
trusted_return_type()
click to toggle source
Returns the type that all the return type of all functions must be assignable to. For `lookup_key` and `data_dig`, that will be the `Puppet::LookupValue` type. For `data_hash` it will be a Hash`
@return [Type] the trusted return type
# File lib/puppet/pops/lookup/function_provider.rb 19 def self.trusted_return_type 20 DataProvider.value_type 21 end
Public Instance Methods
create_function_context(lookup_invocation)
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 37 def create_function_context(lookup_invocation) 38 FunctionContext.new(EnvironmentContext.adapt(lookup_invocation.scope.compiler.environment), module_name, function(lookup_invocation)) 39 end
full_name()
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 49 def full_name 50 "#{self.class::TAG} function '#{@function_name}'" 51 end
function_context(lookup_invocation, location)
click to toggle source
@return [FunctionContext] the function context associated with this provider
# File lib/puppet/pops/lookup/function_provider.rb 33 def function_context(lookup_invocation, location) 34 @contexts[location] ||= create_function_context(lookup_invocation) 35 end
module_name()
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 41 def module_name 42 @parent_data_provider.module_name 43 end
name()
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 45 def name 46 "Hierarchy entry \"#{@name}\"" 47 end
options(location = nil)
click to toggle source
Obtains the options to send to the function, optionally merged with a 'path' or 'uri' option
@param [Pathname,URI] location The location to add to the options @return [Hash{String => Object}] The options hash
# File lib/puppet/pops/lookup/function_provider.rb 61 def options(location = nil) 62 location = location.location unless location.nil? 63 case location 64 when Pathname 65 @options.merge(HieraConfig::KEY_PATH => location.to_s) 66 when URI 67 @options.merge(HieraConfig::KEY_URI => location.to_s) 68 else 69 @options 70 end 71 end
to_s()
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 53 def to_s 54 name 55 end
value_is_validated?()
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 73 def value_is_validated? 74 @value_is_validated 75 end
Private Instance Methods
function(lookup_invocation)
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 79 def function(lookup_invocation) 80 @function ||= load_function(lookup_invocation) 81 end
load_function(lookup_invocation)
click to toggle source
# File lib/puppet/pops/lookup/function_provider.rb 83 def load_function(lookup_invocation) 84 loaders = lookup_invocation.scope.compiler.loaders 85 typed_name = Loader::TypedName.new(:function, @function_name) 86 loader = if typed_name.qualified? 87 qualifier = typed_name.name_parts[0] 88 qualifier == 'environment' ? loaders.private_environment_loader : loaders.private_loader_for_module(qualifier) 89 else 90 loaders.private_environment_loader 91 end 92 te = loader.load_typed(typed_name) 93 if te.nil? || te.value.nil? 94 @parent_data_provider.config(lookup_invocation).fail(Issues::HIERA_DATA_PROVIDER_FUNCTION_NOT_FOUND, 95 :function_type => self.class::TAG, :function_name => @function_name) 96 end 97 func = te.value 98 @value_is_validated = func.class.dispatcher.dispatchers.all? do |dispatcher| 99 rt = dispatcher.type.return_type 100 if rt.nil? 101 false 102 else 103 Types::TypeAsserter.assert_assignable(nil, self.class.trusted_return_type, rt) { "Return type of '#{self.class::TAG}' function named '#{function_name}'" } 104 true 105 end 106 end 107 func 108 end