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

Public Instance Methods

check(name) { || ... } click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
 89 def check(name)
 90   if @name_stack.include?(name)
 91     raise Puppet::DataBinding::RecursiveLookupError, _("Recursive lookup detected in [%{name_stack}]") % { name_stack: @name_stack.join(', ') }
 92   end
 93   return unless block_given?
 94 
 95   @name_stack.push(name)
 96   begin
 97     yield
 98   rescue Puppet::DataBinding::LookupError
 99     raise
100   rescue Puppet::Error => detail
101     raise Puppet::DataBinding::LookupError.new(detail.message, nil, nil, nil, detail)
102   ensure
103     @name_stack.pop
104   end
105 end
emit_debug_info(preamble) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
107 def emit_debug_info(preamble)
108   @explainer.emit_debug_info(preamble) if @explainer.is_a?(DebugExplainer)
109 end
explain_options?() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
165 def explain_options?
166   @explainer.nil? ? false : @explainer.explain_options?
167 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
230 def global_hiera_config_path
231   lookup_adapter.global_hiera_config_path
232 end
global_only?() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
218 def global_only?
219   lookup_adapter.global_only? || (instance_variable_defined?(:@global_only) ? @global_only : false)
220 end
hiera_v3_location_overrides() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
257 def hiera_v3_location_overrides
258   instance_variable_defined?(:@hiera_v3_location_overrides) ? @hiera_v3_location_overrides : EMPTY_ARRAY
259 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
244 def hiera_v3_merge_behavior?
245   instance_variable_defined?(:@hiera_v3_merge_behavior)
246 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
235 def hiera_xxx_call?
236   instance_variable_defined?(:@hiera_xxx_call)
237 end
lookup(key, module_name = nil) { || ... } click to toggle source
   # File lib/puppet/pops/lookup/invocation.rb
72 def lookup(key, module_name = nil)
73   key = LookupKey.new(key) unless key.is_a?(LookupKey)
74   @top_key = key
75   @module_name = module_name.nil? ? key.module_name : module_name
76   save_current = self.class.current
77   if save_current.equal?(self)
78     yield
79   else
80     begin
81       self.class.current = self
82       yield
83     ensure
84       self.class.current = save_current
85     end
86   end
87 end
lookup_adapter() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
111 def lookup_adapter
112   @adapter ||= @adapter_class.adapt(scope.compiler)
113 end
only_explain_options?() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
161 def only_explain_options?
162   @explainer.nil? ? false : @explainer.only_explain_options?
163 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
120 def remember_scope_lookup(*lookup_result)
121   # Does nothing by default
122 end
report_found(key, value) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
179 def report_found(key, value)
180   @explainer.accept_found(key, value) unless @explainer.nil?
181   value
182 end
report_found_in_defaults(key, value) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
174 def report_found_in_defaults(key, value)
175   @explainer.accept_found_in_defaults(key, value) unless @explainer.nil?
176   value
177 end
report_found_in_overrides(key, value) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
169 def report_found_in_overrides(key, value)
170   @explainer.accept_found_in_overrides(key, value) unless @explainer.nil?
171   value
172 end
report_location_not_found() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
200 def report_location_not_found
201   @explainer.accept_location_not_found unless @explainer.nil?
202 end
report_merge_source(merge_source) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
184 def report_merge_source(merge_source)
185   @explainer.accept_merge_source(merge_source) unless @explainer.nil?
186 end
report_module_not_found(module_name) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
204 def report_module_not_found(module_name)
205   @explainer.accept_module_not_found(module_name) unless @explainer.nil?
206 end
report_module_provider_not_found(module_name) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
208 def report_module_provider_not_found(module_name)
209   @explainer.accept_module_provider_not_found(module_name) unless @explainer.nil?
210 end
report_not_found(key) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
196 def report_not_found(key)
197   @explainer.accept_not_found(key) unless @explainer.nil?
198 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
191 def report_result(value)
192   @explainer.accept_result(value) unless @explainer.nil?
193   value
194 end
report_text(&block) click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
212 def report_text(&block)
213   unless @explainer.nil?
214     @explainer.accept_text(block.call)
215   end
216 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
224 def set_global_only
225   @global_only = true
226   self
227 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
253 def set_hiera_v3_location_overrides(overrides)
254   @hiera_v3_location_overrides = [overrides].flatten unless overrides.nil?
255 end
set_hiera_v3_merge_behavior() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
248 def set_hiera_v3_merge_behavior
249   @hiera_v3_merge_behavior = true
250 end
set_hiera_xxx_call() click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
239 def set_hiera_xxx_call
240   @hiera_xxx_call = true
241 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
134 def with(qualifier_type, qualifier)
135   if explainer.nil?
136     yield
137   else
138     @explainer.push(qualifier_type, qualifier)
139     begin
140       yield
141     ensure
142       @explainer.pop
143     end
144   end
145 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
24 def with_scope(scope)
25   yield(Invocation.new(scope, override_values, default_values, explainer))
26 end
without_explain() { || ... } click to toggle source
    # File lib/puppet/pops/lookup/invocation.rb
147 def without_explain
148   if explainer.nil?
149     yield
150   else
151     save_explainer = @explainer
152     begin
153       @explainer = nil
154       yield
155     ensure
156       @explainer = save_explainer
157     end
158   end
159 end

Protected Instance Methods

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