class Puppet::Pops::Lookup::Invocation

@api private

Attributes

adapter_class[R]
default_values[R]
explainer[R]
module_name[R]
override_values[R]
scope[R]
top_key[R]

Public Class Methods

current() click to toggle source
   # File lib/puppet/pops/lookup/invocation.rb
12 def self.current
13   (@current ||= Puppet::ThreadLocal.new(nil)).value
14 end
current=(new_value) click to toggle source
   # File lib/puppet/pops/lookup/invocation.rb
16 def self.current=(new_value)
17   @current.value = new_value
18 end
new(scope, override_values = EMPTY_HASH, default_values = EMPTY_HASH, explainer = nil, adapter_class = nil) click to toggle source

Creates a context object for a lookup invocation. The object contains the current scope, overrides, and default values and may optionally contain an {ExplanationAcceptor} instance that will receive book-keeping information about the progress of the lookup.

If the explain argument is a boolean, then false means that no explanation is needed and true means that the default explanation acceptor should be used. The explain argument may also be an instance of the `ExplanationAcceptor` class.

@param scope [Puppet::Parser::Scope] The scope to use for the lookup @param override_values [Hash<String,Object>|nil] A map to use as override. Values found here are returned immediately (no merge) @param default_values [Hash<String,Object>] A map to use as the last resort (but before default) @param explainer [boolean,Explanainer] An boolean true to use the default explanation acceptor or an explainer instance that will receive information about the lookup

   # File lib/puppet/pops/lookup/invocation.rb
41 def initialize(scope, override_values = EMPTY_HASH, default_values = EMPTY_HASH, explainer = nil, adapter_class = nil)
42   @scope = scope
43   @override_values = override_values
44   @default_values = default_values
45 
46   parent_invocation = self.class.current
47 
48   if parent_invocation && (adapter_class.nil? || adapter_class == parent_invocation.adapter_class)
49     # Inherit from parent invocation (track recursion)
50     @name_stack = parent_invocation.name_stack
51     @adapter_class = parent_invocation.adapter_class
52 
53     # Inherit Hiera 3 legacy properties
54     set_hiera_xxx_call if parent_invocation.hiera_xxx_call?
55     set_hiera_v3_merge_behavior if parent_invocation.hiera_v3_merge_behavior?
56     set_global_only if parent_invocation.global_only?
57     povr = parent_invocation.hiera_v3_location_overrides
58     set_hiera_v3_location_overrides(povr) unless povr.empty?
59 
60     # Inherit explainer unless a new explainer is given or disabled using false
61     explainer = explainer == false ? nil : parent_invocation.explainer
62   else
63     @name_stack = []
64     @adapter_class = adapter_class.nil? ? LookupAdapter : adapter_class
65     unless explainer.is_a?(Explainer)
66       explainer = explainer == true ? Explainer.new : nil
67     end
68     explainer = DebugExplainer.new(explainer) if Puppet[:debug] && !explainer.is_a?(DebugExplainer)
69   end
70   @explainer = explainer
71 end

Public Instance Methods

check(name) { || ... } click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
 90 def check(name)
 91   if @name_stack.include?(name)
 92     raise Puppet::DataBinding::RecursiveLookupError, _("Recursive lookup detected in [%{name_stack}]") % { name_stack: @name_stack.join(', ') }
 93   end
 94   return unless block_given?
 95 
 96   @name_stack.push(name)
 97   begin
 98     yield
 99   rescue Puppet::DataBinding::LookupError
100     raise
101   rescue Puppet::Error => detail
102     raise Puppet::DataBinding::LookupError.new(detail.message, nil, nil, nil, detail)
103   ensure
104     @name_stack.pop
105   end
106 end
emit_debug_info(preamble) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
108 def emit_debug_info(preamble)
109   @explainer.emit_debug_info(preamble) if @explainer.is_a?(DebugExplainer)
110 end
explain_options?() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
166 def explain_options?
167   @explainer.nil? ? false : @explainer.explain_options?
168 end
global_hiera_config_path() click to toggle source

@return [Pathname] the full path of the hiera.yaml config file

    # File lib/puppet/pops/lookup/invocation.rb
231 def global_hiera_config_path
232   lookup_adapter.global_hiera_config_path
233 end
global_only?() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
219 def global_only?
220   lookup_adapter.global_only? || (instance_variable_defined?(:@global_only) ? @global_only : false)
221 end
hiera_v3_location_overrides() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
258 def hiera_v3_location_overrides
259   instance_variable_defined?(:@hiera_v3_location_overrides) ? @hiera_v3_location_overrides : EMPTY_ARRAY
260 end
hiera_v3_merge_behavior?() click to toggle source

@return [Boolean] `true` if the invocation stems from the hiera_xxx function family

    # File lib/puppet/pops/lookup/invocation.rb
245 def hiera_v3_merge_behavior?
246   instance_variable_defined?(:@hiera_v3_merge_behavior)
247 end
hiera_xxx_call?() click to toggle source

@return [Boolean] `true` if the invocation stems from the hiera_xxx function family

    # File lib/puppet/pops/lookup/invocation.rb
236 def hiera_xxx_call?
237   instance_variable_defined?(:@hiera_xxx_call)
238 end
lookup(key, module_name = nil) { || ... } click to toggle source
   # File lib/puppet/pops/lookup/invocation.rb
73 def lookup(key, module_name = nil)
74   key = LookupKey.new(key) unless key.is_a?(LookupKey)
75   @top_key = key
76   @module_name = module_name.nil? ? key.module_name : module_name
77   save_current = self.class.current
78   if save_current.equal?(self)
79     yield
80   else
81     begin
82       self.class.current = self
83       yield
84     ensure
85       self.class.current = save_current
86     end
87   end
88 end
lookup_adapter() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
112 def lookup_adapter
113   @adapter ||= @adapter_class.adapt(scope.compiler)
114 end
only_explain_options?() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
162 def only_explain_options?
163   @explainer.nil? ? false : @explainer.only_explain_options?
164 end
remember_scope_lookup(*lookup_result) click to toggle source

This method is overridden by the special Invocation used while resolving interpolations in a Hiera configuration file (hiera.yaml) where it's used for collecting and remembering the current values that the configuration was based on

@api private

    # File lib/puppet/pops/lookup/invocation.rb
121 def remember_scope_lookup(*lookup_result)
122   # Does nothing by default
123 end
report_found(key, value) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
180 def report_found(key, value)
181   @explainer.accept_found(key, value) unless @explainer.nil?
182   value
183 end
report_found_in_defaults(key, value) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
175 def report_found_in_defaults(key, value)
176   @explainer.accept_found_in_defaults(key, value) unless @explainer.nil?
177   value
178 end
report_found_in_overrides(key, value) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
170 def report_found_in_overrides(key, value)
171   @explainer.accept_found_in_overrides(key, value) unless @explainer.nil?
172   value
173 end
report_location_not_found() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
201 def report_location_not_found
202   @explainer.accept_location_not_found unless @explainer.nil?
203 end
report_merge_source(merge_source) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
185 def report_merge_source(merge_source)
186   @explainer.accept_merge_source(merge_source) unless @explainer.nil?
187 end
report_module_not_found(module_name) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
205 def report_module_not_found(module_name)
206   @explainer.accept_module_not_found(module_name) unless @explainer.nil?
207 end
report_module_provider_not_found(module_name) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
209 def report_module_provider_not_found(module_name)
210   @explainer.accept_module_provider_not_found(module_name) unless @explainer.nil?
211 end
report_not_found(key) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
197 def report_not_found(key)
198   @explainer.accept_not_found(key) unless @explainer.nil?
199 end
report_result(value) click to toggle source

Report the result of a merge or fully resolved interpolated string @param value [Object] The result to report @return [Object] the given value

    # File lib/puppet/pops/lookup/invocation.rb
192 def report_result(value)
193   @explainer.accept_result(value) unless @explainer.nil?
194   value
195 end
report_text(&block) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
213 def report_text(&block)
214   unless @explainer.nil?
215     @explainer.accept_text(block.call)
216   end
217 end
set_global_only() click to toggle source

Instructs the lookup framework to only perform lookups in the global layer @return [Invocation] self

    # File lib/puppet/pops/lookup/invocation.rb
225 def set_global_only
226   @global_only = true
227   self
228 end
set_hiera_v3_location_overrides(overrides) click to toggle source

Overrides passed from hiera_xxx functions down to V3DataHashFunctionProvider

    # File lib/puppet/pops/lookup/invocation.rb
254 def set_hiera_v3_location_overrides(overrides)
255   @hiera_v3_location_overrides = [overrides].flatten unless overrides.nil?
256 end
set_hiera_v3_merge_behavior() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
249 def set_hiera_v3_merge_behavior
250   @hiera_v3_merge_behavior = true
251 end
set_hiera_xxx_call() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
240 def set_hiera_xxx_call
241   @hiera_xxx_call = true
242 end
with(qualifier_type, qualifier) { || ... } click to toggle source

The qualifier_type can be one of: :global - qualifier is the data binding terminus name :data_provider - qualifier a DataProvider instance :path - qualifier is a ResolvedPath instance :merge - qualifier is a MergeStrategy instance :interpolation - qualifier is the unresolved interpolation expression :meta - qualifier is the module name :data - qualifier is the key

@param qualifier [Object] A branch, a provider, or a path

    # File lib/puppet/pops/lookup/invocation.rb
135 def with(qualifier_type, qualifier)
136   if explainer.nil?
137     yield
138   else
139     @explainer.push(qualifier_type, qualifier)
140     begin
141       yield
142     ensure
143       @explainer.pop
144     end
145   end
146 end
with_scope(scope) { |invocation| ... } click to toggle source

Creates a new instance with same settings as this instance but with a new given scope and yields with that scope.

@param scope [Puppet::Parser::Scope] The new scope @return [Invocation] the new instance

   # File lib/puppet/pops/lookup/invocation.rb
25 def with_scope(scope)
26   yield(Invocation.new(scope, override_values, default_values, explainer))
27 end
without_explain() { || ... } click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
148 def without_explain
149   if explainer.nil?
150     yield
151   else
152     save_explainer = @explainer
153     begin
154       @explainer = nil
155       yield
156     ensure
157       @explainer = save_explainer
158     end
159   end
160 end

Protected Instance Methods

name_stack() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
264 def name_stack
265   @name_stack.clone
266 end