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

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

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConfiguredDataProvider

#config, #config_path, #name, #unchecked_key_lookup

Methods included from DataProvider

ensure_types_initialized, #key_lookup, key_type, #lookup, #name, #unchecked_key_lookup, #validate_data_value, 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.



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.



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

def module_name
  @module_name
end

Instance Method Details

#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.



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

def place
  'Module'
end

#validate_data_hash(data_provider, 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:

  • data_hash (Hash)

    The data hash

Returns:

  • (Hash)

    The possibly pruned hash



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

def validate_data_hash(data_provider, 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 = '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}': #{data_provider.name} #{msg}")
    memo
  end
end