Class: Puppet::DataProviders::FunctionModuleDataProvider

Inherits:
Plugins::DataProviders::ModuleDataProvider show all
Includes:
DataFunctionSupport
Defined in:
lib/puppet/data_providers/function_module_data_provider.rb

Overview

The FunctionModuleDataProvider provides data from a function called ‘environment::data()’ that resides in a directory environment (seen as a module with the name environment). The function is called on demand, and is associated with the compiler via an Adapter. This ensures that the data is only produced once per compilation.

Constant Summary collapse

MODULE_NAME =
'module_name'.freeze

Instance Method Summary collapse

Methods included from DataFunctionSupport

#data, #initialize_data_from_function

Instance Method Details

#loader(key, scope) ⇒ Object



36
37
38
# File 'lib/puppet/data_providers/function_module_data_provider.rb', line 36

def loader(key, scope)
  scope.compiler.loaders.private_loader_for_module(key)
end

#lookup(name, scope, merge) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet/data_providers/function_module_data_provider.rb', line 15

def lookup(name, scope, merge)
  # Do not attempt to do a lookup in a module unless the name is qualified.
  qual_index = name.index('::')
  throw :no_such_key if qual_index.nil?
  module_name = name[0..qual_index-1]
  begin
    hash = data(module_name, scope) do | data |
      module_prefix = "#{module_name}::"
      data.each_pair do |k,v|
        unless k.is_a?(String) && k.start_with?(module_prefix)
          raise Puppet::Error, "Module data for module '#{module_name}' must use keys qualified with the name of the module"
        end
      end
    end
    throw :no_such_key unless hash.include?(name)
    hash[name]
  rescue *Puppet::Error => detail
    raise Puppet::DataBinding::LookupError.new(detail.message, detail)
  end
end