Class: Puppet::Pops::Lookup::ModuleDataProvider Private

Inherits:
ConfiguredDataProvider show all
Defined in:
lib/puppet/pops/lookup/module_data_provider.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConfiguredDataProvider

#config, #config=, #config_path, #name, #unchecked_key_lookup

Methods included from DataProvider

#key_lookup, key_type, #lookup, #name, register_types, #unchecked_key_lookup, #validate_data_value, #value_is_validated?, value_type

Constructor Details

#initialize(module_name, config = nil) ⇒ ModuleDataProvider

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ModuleDataProvider.

API:

  • private



10
11
12
13
# File 'lib/puppet/pops/lookup/module_data_provider.rb', line 10

def initialize(module_name, config = nil)
  super(config)
  @module_name = module_name
end

Instance Attribute Details

#module_nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



8
9
10
# File 'lib/puppet/pops/lookup/module_data_provider.rb', line 8

def module_name
  @module_name
end

Instance Method Details

#key_lookup_in_default(key, lookup_invocation, merge) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • The key to lookup

  • The current lookup invocation

  • Merge strategy or hash with strategy and options

API:

  • private



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet/pops/lookup/module_data_provider.rb', line 25

def key_lookup_in_default(key, lookup_invocation, merge)
  dps = config(lookup_invocation).configured_data_providers(lookup_invocation, self, true)
  if dps.empty?
    lookup_invocation.report_not_found(key)
    throw :no_such_key
  end
  merge_strategy = MergeStrategy.strategy(merge)
  lookup_invocation.check(key.to_s) do
    lookup_invocation.with(:data_provider, self) do
      merge_strategy.lookup(dps, lookup_invocation) do |data_provider|
        data_provider.unchecked_key_lookup(key, lookup_invocation, merge_strategy)
      end
    end
  end
end

#placeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



15
16
17
# File 'lib/puppet/pops/lookup/module_data_provider.rb', line 15

def place
  'Module'
end

#validate_data_hash(data_hash) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Parameters:

  • The data hash

Returns:

  • The possibly pruned hash

API:

  • private



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/puppet/pops/lookup/module_data_provider.rb', line 46

def validate_data_hash(data_hash)
  super
  module_prefix = "#{module_name}::"
  data_hash.each_key.reduce(data_hash) do |memo, k|
    next memo if k == LOOKUP_OPTIONS || k.start_with?(module_prefix)
    msg = "#{yield} must use keys qualified with the name of the module"
    memo = memo.clone if memo.equal?(data_hash)
    memo.delete(k)
    Puppet.warning("Module '#{module_name}': #{msg}")
    memo
  end
  data_hash
end