Class: Puppet::Plugins::DataProviders::PathBasedDataProvider Abstract

Inherits:
Object
  • Object
show all
Includes:
DataProvider
Defined in:
lib/puppet/plugins/data_providers/data_provider.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DataProvider

#lookup, #post_process

Constructor Details

#initialize(name, paths) ⇒ PathBasedDataProvider

Returns a new instance of PathBasedDataProvider.

Parameters:

  • name (String)

    The name of the data provider

  • paths (Array<ResolvedPath>)

    Paths used by this provider

Since:

  • Puppet 4.0.0



180
181
182
183
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 180

def initialize(name, paths)
  @name = name
  @paths = paths
end

Instance Attribute Details

#nameObject (readonly)

Since:

  • Puppet 4.0.0



174
175
176
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 174

def name
  @name
end

Instance Method Details

#unchecked_lookup(key, lookup_invocation, merge) ⇒ Object

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



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/puppet/plugins/data_providers/data_provider.rb', line 193

def unchecked_lookup(key, lookup_invocation, merge)
  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(:path, path) do
          if path.exists?
            hash = data(path.path, lookup_invocation)
            value = hash[key]
            if value || hash.include?(key)
              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_path_not_found
            throw :no_such_key
          end
        end
      end
      lookup_invocation.report_result(merged_result)
    end
  end
end