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
22 def initialize(name, parent_data_provider, function_name, options, locations)
23   @name = name
24   @parent_data_provider = parent_data_provider
25   @function_name = function_name
26   @options = options
27   @locations = locations || [nil]
28   @contexts = {}
29 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
18 def self.trusted_return_type
19   DataProvider.value_type
20 end

Public Instance Methods

create_function_context(lookup_invocation) click to toggle source
   # File lib/puppet/pops/lookup/function_provider.rb
36 def create_function_context(lookup_invocation)
37   FunctionContext.new(EnvironmentContext.adapt(lookup_invocation.scope.compiler.environment), module_name, function(lookup_invocation))
38 end
full_name() click to toggle source
   # File lib/puppet/pops/lookup/function_provider.rb
48 def full_name
49   "#{self.class::TAG} function '#{@function_name}'"
50 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
32 def function_context(lookup_invocation, location)
33   @contexts[location] ||= create_function_context(lookup_invocation)
34 end
module_name() click to toggle source
   # File lib/puppet/pops/lookup/function_provider.rb
40 def module_name
41   @parent_data_provider.module_name
42 end
name() click to toggle source
   # File lib/puppet/pops/lookup/function_provider.rb
44 def name
45   "Hierarchy entry \"#{@name}\""
46 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
60 def options(location = nil)
61   location = location.location unless location.nil?
62   case location
63   when Pathname
64     @options.merge(HieraConfig::KEY_PATH => location.to_s)
65   when URI
66     @options.merge(HieraConfig::KEY_URI => location.to_s)
67   else
68     @options
69   end
70 end
to_s() click to toggle source
   # File lib/puppet/pops/lookup/function_provider.rb
52 def to_s
53   name
54 end
value_is_validated?() click to toggle source
   # File lib/puppet/pops/lookup/function_provider.rb
72 def value_is_validated?
73   @value_is_validated
74 end

Private Instance Methods

function(lookup_invocation) click to toggle source
   # File lib/puppet/pops/lookup/function_provider.rb
78 def function(lookup_invocation)
79   @function ||= load_function(lookup_invocation)
80 end
load_function(lookup_invocation) click to toggle source
    # File lib/puppet/pops/lookup/function_provider.rb
 82 def load_function(lookup_invocation)
 83   loaders = lookup_invocation.scope.compiler.loaders
 84   typed_name = Loader::TypedName.new(:function, @function_name)
 85   loader = if typed_name.qualified?
 86     qualifier = typed_name.name_parts[0]
 87     qualifier == 'environment' ? loaders.private_environment_loader : loaders.private_loader_for_module(qualifier)
 88   else
 89     loaders.private_environment_loader
 90   end
 91   te = loader.load_typed(typed_name)
 92   if te.nil? || te.value.nil?
 93     @parent_data_provider.config(lookup_invocation).fail(Issues::HIERA_DATA_PROVIDER_FUNCTION_NOT_FOUND,
 94       :function_type => self.class::TAG, :function_name => @function_name)
 95   end
 96   func = te.value
 97   @value_is_validated = func.class.dispatcher.dispatchers.all? do |dispatcher|
 98     rt = dispatcher.type.return_type
 99     if rt.nil?
100       false
101     else
102       Types::TypeAsserter.assert_assignable(nil, self.class.trusted_return_type, rt) { "Return type of '#{self.class::TAG}' function named '#{function_name}'" }
103       true
104     end
105   end
106   func
107 end