Class: Puppet::Plugins::DataProviders::ModuleDataProvider
- Includes:
- DataProvider
- Defined in:
- lib/puppet/plugins/data_providers/data_provider.rb
Overview
Direct Known Subclasses
DataProviders::FunctionModuleDataProvider, DataProviders::HieraModuleDataProvider
Constant Summary collapse
- LOOKUP_OPTIONS =
Puppet::Pops::Lookup::LOOKUP_OPTIONS
Instance Method Summary collapse
-
#data_key(key, lookup_invocation) ⇒ String
Retrieve the first segment of the qualified name key.
-
#validate_data(data, module_name) ⇒ Hash
Asserts that all keys in the given data are prefixed with the given module_name.
Methods included from DataProvider
#lookup, #name, #post_process, #unchecked_lookup
Instance Method Details
#data_key(key, lookup_invocation) ⇒ String
Retrieve the first segment of the qualified name key. This method will throw :no_such_key unless the segment can be extracted.
107 108 109 110 111 112 |
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 107 def data_key(key, lookup_invocation) return lookup_invocation.module_name if key == LOOKUP_OPTIONS qual_index = key.index('::') throw :no_such_key if qual_index.nil? key[0..qual_index-1] end |
#validate_data(data, module_name) ⇒ Hash
Asserts that all keys in the given data are prefixed with the given module_name. Remove entries that does not follow the convention and log a warning.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 121 def validate_data(data, module_name) module_prefix = "#{module_name}::" data.each_key.reduce(data) do |memo, k| if k.is_a?(String) next memo if k == LOOKUP_OPTIONS || k.start_with?(module_prefix) msg = 'must use keys qualified with the name of the module' else msg = "must use keys of type String, got #{k.class.name}" end memo = memo.clone if memo.equal?(data) memo.delete(k) Puppet.warning("Module data for module '#{module_name}' #{msg}") memo end end |