Class: Puppet::Plugins::DataProviders::ModuleDataProvider Deprecated Private

Inherits:
Object
  • Object
show all
Includes:
DataProvider
Defined in:
lib/puppet/plugins/data_providers/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.

Deprecated.

TODO: API 5.0 Remove this class

Since:

  • Puppet 4.0.0

Constant Summary collapse

LOOKUP_OPTIONS =

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

Since:

  • Puppet 4.0.0

'lookup_options'.freeze

Constants included from Puppet::Pops::Lookup::SubLookup

Puppet::Pops::Lookup::SubLookup::SPECIAL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DataProvider

#key_lookup, #lookup, #name, #post_process, #unchecked_key_lookup, #unchecked_lookup

Methods included from Puppet::Pops::Lookup::Interpolation

#interpolate

Methods included from Puppet::Pops::Lookup::SubLookup

#split_key, #sub_lookup

Methods included from Puppet::Pops::Lookup::DataProvider

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

Constructor Details

#initialize(module_name = 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.

Since:

  • Puppet 4.0.0



132
133
134
135
136
137
138
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 132

def initialize(module_name = nil)
  unless Puppet[:strict] == :off
    Puppet.warn_once(:deprecation, 'Plugins::DataProviders::ModuleDataProvider',
      'Plugins::DataProviders::ModuleDataProvider is deprecated and will be removed in the next major version of Puppet')
  end
  @module_name = module_name || Puppet::Pops::Lookup::Invocation.current.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.

Since:

  • Puppet 4.0.0



130
131
132
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 130

def module_name
  @module_name
end

Instance Method Details

#data_key(key, lookup_invocation) ⇒ String

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.

Deprecated.

Retrieve the first segment of the qualified name key. This method will throw :no_such_key unless the segment can be extracted.

Parameters:

  • key (String)

    The key

Returns:

  • (String)

    The first segment of the given key

Since:

  • Puppet 4.0.0



147
148
149
150
151
152
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 147

def data_key(key, lookup_invocation)
  return 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.

Parameters:

  • data (Hash)

    The data hash

  • module_name (String)

    The name of the module where the data was found

Returns:

  • (Hash)

    The possibly pruned hash

Since:

  • Puppet 4.0.0



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 161

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