Class: Puppet::Plugins::DataProviders::PathBasedDataProvider Abstract 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.
This class is abstract.

A data provider that is initialized with a set of paths. When performing lookup, each path is search in the order they appear. If a value is found in more than one location it will be merged according to a given (optional) merge strategy.

Since:

  • Puppet 4.0.0

Constant Summary

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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DataProvider

#data_key, #key_lookup, #lookup, #post_process, #unchecked_key_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, #module_name, register_types, #unchecked_key_lookup, #validate_data_hash, #validate_data_value, #value_is_validated?, value_type

Constructor Details

#initialize(name, paths, parent_data_provider = nil) ⇒ PathBasedDataProvider

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.

Returns a new instance of PathBasedDataProvider.

Parameters:

  • name (String)

    The name of the data provider

  • paths (Array<ResolvedPath>)

    Paths used by this provider

  • parent_data_provider (DataProvider) (defaults to: nil)

    The data provider that is the container of this data provider

Since:

  • Puppet 4.0.0



240
241
242
243
244
245
246
247
248
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 240

def initialize(name, paths, parent_data_provider = nil)
  unless Puppet[:strict] == :off
    Puppet.warn_once(:deprecation, 'PathBasedDataProvider',
      'PathBasedDataProvider is deprecated and will be removed in the next major version of Puppet')
  end
  @name = name
  @paths = paths
  @parent_data_provider = parent_data_provider
end

Instance Attribute Details

#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



234
235
236
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 234

def name
  @name
end

Instance Method Details

#load_data(path, data_key, lookup_invocation) ⇒ 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.

Deprecated.

Gets the data from the compiler, or initializes it by calling #initialize_data if not present in the compiler. This means, that data is initialized once per compilation, and the data is cached for as long as the compiler lives (which is for one catalog production). This makes it possible to return data that is tailored for the request.

If data is obtained using the #initialize_data method it will be sent to the #validate_data for validation

Parameters:

  • path (String)

    The path to the data to be loaded (passed to #initialize_data)

  • data_key (String)

    The data key such as the name of a module or the constant ‘environment’

  • lookup_invocation (Puppet::Pops::Lookup::Invocation)

    The current lookup invocation

  • merge (String|Hash<String,Object>|nil)

    Merge strategy or hash with strategy and options

Returns:

  • (Hash)

    The data hash for the given key

Since:

  • Puppet 4.0.0



263
264
265
266
267
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 263

def load_data(path, data_key, lookup_invocation)
  compiler = lookup_invocation.scope.compiler
  adapter = Puppet::DataProviders::DataAdapter.get(compiler) || Puppet::DataProviders::DataAdapter.adapt(compiler)
  adapter.data[path] ||= validate_data(initialize_data(path, lookup_invocation), data_key)
end

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

Deprecated.

Performs a lookup by searching all given paths for the given key. A merge will be performed if the value is found in more than one location and merge is not nil.

Parameters:

Since:

  • Puppet 4.0.0



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 282

def unchecked_lookup(key, lookup_invocation, merge)
  segments = split_key(key)
  root_key = segments.shift

  module_name = @parent_data_provider.nil? ? nil : @parent_data_provider.data_key(key, lookup_invocation)
  lookup_invocation.with(:data_provider, self) do
    merge_strategy = Puppet::Pops::MergeStrategy.strategy(merge)
    lookup_invocation.with(:merge, merge_strategy) do
      merged_result = merge_strategy.merge_lookup(@paths) do |path|
        lookup_invocation.with(:location, path) do
          if path.exists?
            hash = load_data(path.path, module_name, lookup_invocation)
            value = hash[root_key]
            if value || hash.include?(root_key)
              value = sub_lookup(key, lookup_invocation, segments, value) unless segments.empty?
              lookup_invocation.report_found(key, post_process(value, lookup_invocation))
            else
              lookup_invocation.report_not_found(key)
              throw :no_such_key
            end
          else
            lookup_invocation.report_location_not_found
            throw :no_such_key
          end
        end
      end
      lookup_invocation.report_result(merged_result)
    end
  end
end

#validate_data(data, module_name) ⇒ 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.

Deprecated.

Since:

  • Puppet 4.0.0



271
272
273
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 271

def validate_data(data, module_name)
  @parent_data_provider.nil? ? data : @parent_data_provider.validate_data(data, module_name)
end