class Puppet::Pops::Lookup::ModuleDataProvider

@api private

Attributes

module_name[R]

Public Class Methods

new(module_name, config = nil) click to toggle source
   # File lib/puppet/pops/lookup/module_data_provider.rb
11 def initialize(module_name, config = nil)
12   super(config)
13   @module_name = module_name
14 end

Public Instance Methods

key_lookup_in_default(key, lookup_invocation, merge) click to toggle source

Performs a lookup using a module default hierarchy with an endless recursion check.

@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 or hash with strategy and options

   # File lib/puppet/pops/lookup/module_data_provider.rb
26 def key_lookup_in_default(key, lookup_invocation, merge)
27   dps = config(lookup_invocation).configured_data_providers(lookup_invocation, self, true)
28   if dps.empty?
29     lookup_invocation.report_not_found(key)
30     throw :no_such_key
31   end
32   merge_strategy = MergeStrategy.strategy(merge)
33   lookup_invocation.check(key.to_s) do
34     lookup_invocation.with(:data_provider, self) do
35       merge_strategy.lookup(dps, lookup_invocation) do |data_provider|
36         data_provider.unchecked_key_lookup(key, lookup_invocation, merge_strategy)
37       end
38     end
39   end
40 end
place() click to toggle source
   # File lib/puppet/pops/lookup/module_data_provider.rb
16 def place
17   'Module'
18 end
validate_data_hash(data_hash) click to toggle source

Asserts that all keys in the given data_hash are prefixed with the configured module_name. Removes entries that does not follow the convention and logs a warning.

@param data_hash [Hash] The data hash @return [Hash] The possibly pruned hash

   # File lib/puppet/pops/lookup/module_data_provider.rb
47 def validate_data_hash(data_hash)
48   super
49   module_prefix = "#{module_name}::"
50   data_hash.each_key.reduce(data_hash) do |memo, k|
51     next memo if k == LOOKUP_OPTIONS || k.start_with?(module_prefix)
52     msg = "#{yield} must use keys qualified with the name of the module"
53     memo = memo.clone if memo.equal?(data_hash)
54     memo.delete(k)
55     Puppet.warning("Module '#{module_name}': #{msg}")
56     memo
57   end
58   data_hash
59 end

Protected Instance Methods

assert_config_version(config) click to toggle source
   # File lib/puppet/pops/lookup/module_data_provider.rb
63 def assert_config_version(config)
64   if config.version > 3
65     config
66   else
67     if Puppet[:strict] == :error
68       config.fail(Issues::HIERA_VERSION_3_NOT_GLOBAL, :where => 'module')
69     else
70       Puppet.warn_once(:hiera_v3_at_module_root, config.config_path, _('hiera.yaml version 3 found at module root was ignored'), config.config_path)
71     end
72     nil
73   end
74 end
provider_root(lookup_invocation) click to toggle source

Return the root of the module with the name equal to the configured module name

@param lookup_invocation [Invocation] The current lookup invocation @return [Pathname] Path to root of the module @raise [Puppet::DataBinding::LookupError] if the module can not be found

   # File lib/puppet/pops/lookup/module_data_provider.rb
82 def provider_root(lookup_invocation)
83   env = lookup_invocation.scope.environment
84   mod = env.module(module_name)
85   raise Puppet::DataBinding::LookupError, _("Environment '%{env}', cannot find module '%{module_name}'") % { env: env.name, module_name: module_name } unless mod
86   Pathname.new(mod.path)
87 end