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
10 def initialize(module_name, config = nil)
11   super(config)
12   @module_name = module_name
13 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
25 def key_lookup_in_default(key, lookup_invocation, merge)
26   dps = config(lookup_invocation).configured_data_providers(lookup_invocation, self, true)
27   if dps.empty?
28     lookup_invocation.report_not_found(key)
29     throw :no_such_key
30   end
31   merge_strategy = MergeStrategy.strategy(merge)
32   lookup_invocation.check(key.to_s) do
33     lookup_invocation.with(:data_provider, self) do
34       merge_strategy.lookup(dps, lookup_invocation) do |data_provider|
35         data_provider.unchecked_key_lookup(key, lookup_invocation, merge_strategy)
36       end
37     end
38   end
39 end
place() click to toggle source
   # File lib/puppet/pops/lookup/module_data_provider.rb
15 def place
16   'Module'
17 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
46 def validate_data_hash(data_hash)
47   super
48   module_prefix = "#{module_name}::"
49   data_hash.each_key.reduce(data_hash) do |memo, k|
50     next memo if k == LOOKUP_OPTIONS || k.start_with?(module_prefix)
51     msg = "#{yield} must use keys qualified with the name of the module"
52     memo = memo.clone if memo.equal?(data_hash)
53     memo.delete(k)
54     Puppet.warning("Module '#{module_name}': #{msg}")
55     memo
56   end
57   data_hash
58 end

Protected Instance Methods

assert_config_version(config) click to toggle source
   # File lib/puppet/pops/lookup/module_data_provider.rb
62 def assert_config_version(config)
63   if config.version > 3
64     config
65   else
66     if Puppet[:strict] == :error
67       config.fail(Issues::HIERA_VERSION_3_NOT_GLOBAL, :where => 'module')
68     else
69       Puppet.warn_once(:hiera_v3_at_module_root, config.config_path, _('hiera.yaml version 3 found at module root was ignored'), config.config_path)
70     end
71     nil
72   end
73 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
81 def provider_root(lookup_invocation)
82   env = lookup_invocation.scope.environment
83   mod = env.module(module_name)
84   raise Puppet::DataBinding::LookupError, _("Environment '%{env}', cannot find module '%{module_name}'") % { env: env.name, module_name: module_name } unless mod
85   Pathname.new(mod.path)
86 end