Class: Puppet::Plugins::DataProviders::PathBasedDataProvider Abstract
- 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.
Direct Known Subclasses
DataProviders::JsonDataProvider, DataProviders::YamlDataProvider
Instance Attribute Summary collapse
- #name ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(name, paths) ⇒ PathBasedDataProvider
constructor
A new instance of PathBasedDataProvider.
-
#unchecked_lookup(key, lookup_invocation, merge) ⇒ Object
Performs a lookup by searching all given paths for the given key.
Methods included from DataProvider
Constructor Details
#initialize(name, paths) ⇒ PathBasedDataProvider
Returns a new instance of PathBasedDataProvider.
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
#name ⇒ Object (readonly)
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.
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 |