Class: Puppet::Pops::Lookup::Invocation Private
- Defined in:
- lib/puppet/pops/lookup/invocation.rb
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.
Direct Known Subclasses
Instance Attribute Summary collapse
- #adapter_class ⇒ Object readonly private
- #default_values ⇒ Object readonly private
- #explainer ⇒ Object readonly private
- #module_name ⇒ Object readonly private
- #override_values ⇒ Object readonly private
- #scope ⇒ Object readonly private
- #top_key ⇒ Object readonly private
Class Method Summary collapse
- .current ⇒ Object private
- .current=(new_value) ⇒ Object private
Instance Method Summary collapse
- #check(name) ⇒ Object private
- #emit_debug_info(preamble) ⇒ Object private
- #explain_options? ⇒ Boolean private
-
#global_hiera_config_path ⇒ Pathname
private
The full path of the hiera.yaml config file.
- #global_only? ⇒ Boolean private
- #hiera_v3_location_overrides ⇒ Object private
-
#hiera_v3_merge_behavior? ⇒ Boolean
private
‘true` if the invocation stems from the hiera_xxx function family.
-
#hiera_xxx_call? ⇒ Boolean
private
‘true` if the invocation stems from the hiera_xxx function family.
-
#initialize(scope, override_values = EMPTY_HASH, default_values = EMPTY_HASH, explainer = nil, adapter_class = nil) ⇒ Invocation
constructor
private
Creates a context object for a lookup invocation.
- #lookup(key, module_name = nil) ⇒ Object private
- #lookup_adapter ⇒ Object private
- #only_explain_options? ⇒ Boolean private
-
#remember_scope_lookup(*lookup_result) ⇒ Object
private
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.
- #report_found(key, value) ⇒ Object private
- #report_found_in_defaults(key, value) ⇒ Object private
- #report_found_in_overrides(key, value) ⇒ Object private
- #report_location_not_found ⇒ Object private
- #report_merge_source(merge_source) ⇒ Object private
- #report_module_not_found(module_name) ⇒ Object private
- #report_module_provider_not_found(module_name) ⇒ Object private
- #report_not_found(key) ⇒ Object private
-
#report_result(value) ⇒ Object
private
Report the result of a merge or fully resolved interpolated string.
- #report_text(&block) ⇒ Object private
-
#set_global_only ⇒ Invocation
private
Instructs the lookup framework to only perform lookups in the global layer.
-
#set_hiera_v3_location_overrides(overrides) ⇒ Object
private
Overrides passed from hiera_xxx functions down to V3DataHashFunctionProvider.
- #set_hiera_v3_merge_behavior ⇒ Object private
- #set_hiera_xxx_call ⇒ Object private
-
#with(qualifier_type, qualifier) ⇒ Object
private
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.
-
#with_scope(scope) {|Invocation.new(scope, override_values, default_values, explainer)| ... } ⇒ Invocation
private
Creates a new instance with same settings as this instance but with a new given scope and yields with that scope.
- #without_explain ⇒ Object private
Constructor Details
#initialize(scope, override_values = EMPTY_HASH, default_values = EMPTY_HASH, explainer = nil, adapter_class = nil) ⇒ Invocation
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.
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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 41 def initialize(scope, override_values = EMPTY_HASH, default_values = EMPTY_HASH, explainer = nil, adapter_class = nil) @scope = scope @override_values = override_values @default_values = default_values parent_invocation = self.class.current if parent_invocation && (adapter_class.nil? || adapter_class == parent_invocation.adapter_class) # Inherit from parent invocation (track recursion) @name_stack = parent_invocation.name_stack @adapter_class = parent_invocation.adapter_class # Inherit Hiera 3 legacy properties set_hiera_xxx_call if parent_invocation.hiera_xxx_call? set_hiera_v3_merge_behavior if parent_invocation.hiera_v3_merge_behavior? set_global_only if parent_invocation.global_only? povr = parent_invocation.hiera_v3_location_overrides set_hiera_v3_location_overrides(povr) unless povr.empty? # Inherit explainer unless a new explainer is given or disabled using false explainer = explainer == false ? nil : parent_invocation.explainer else @name_stack = [] @adapter_class = adapter_class.nil? ? LookupAdapter : adapter_class unless explainer.is_a?(Explainer) explainer = explainer == true ? Explainer.new : nil end explainer = DebugExplainer.new(explainer) if Puppet[:debug] && !explainer.is_a?(DebugExplainer) end @explainer = explainer end |
Instance Attribute Details
#adapter_class ⇒ Object (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.
10 11 12 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 10 def adapter_class @adapter_class end |
#default_values ⇒ Object (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.
10 11 12 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 10 def default_values @default_values end |
#explainer ⇒ Object (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.
10 11 12 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 10 def explainer @explainer end |
#module_name ⇒ Object (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.
10 11 12 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 10 def module_name @module_name end |
#override_values ⇒ Object (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.
10 11 12 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 10 def override_values @override_values end |
#scope ⇒ Object (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.
10 11 12 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 10 def scope @scope end |
#top_key ⇒ Object (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.
10 11 12 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 10 def top_key @top_key end |
Class Method Details
.current ⇒ 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.
12 13 14 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 12 def self.current (@current ||= Puppet::ThreadLocal.new(nil)).value end |
.current=(new_value) ⇒ 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.
16 17 18 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 16 def self.current=(new_value) @current.value = new_value end |
Instance Method Details
#check(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.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 90 def check(name) if @name_stack.include?(name) raise Puppet::DataBinding::RecursiveLookupError, _("Recursive lookup detected in [%{name_stack}]") % { name_stack: @name_stack.join(', ') } end return unless block_given? @name_stack.push(name) begin yield rescue Puppet::DataBinding::LookupError raise rescue Puppet::Error => detail raise Puppet::DataBinding::LookupError.new(detail., nil, nil, nil, detail) ensure @name_stack.pop end end |
#emit_debug_info(preamble) ⇒ 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.
108 109 110 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 108 def emit_debug_info(preamble) @explainer.emit_debug_info(preamble) if @explainer.is_a?(DebugExplainer) end |
#explain_options? ⇒ Boolean
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.
166 167 168 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 166 def @explainer.nil? ? false : @explainer. end |
#global_hiera_config_path ⇒ Pathname
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.
Returns the full path of the hiera.yaml config file.
231 232 233 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 231 def global_hiera_config_path lookup_adapter.global_hiera_config_path end |
#global_only? ⇒ Boolean
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.
219 220 221 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 219 def global_only? lookup_adapter.global_only? || (instance_variable_defined?(:@global_only) ? @global_only : false) end |
#hiera_v3_location_overrides ⇒ 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.
258 259 260 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 258 def hiera_v3_location_overrides instance_variable_defined?(:@hiera_v3_location_overrides) ? @hiera_v3_location_overrides : EMPTY_ARRAY end |
#hiera_v3_merge_behavior? ⇒ Boolean
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.
Returns ‘true` if the invocation stems from the hiera_xxx function family.
245 246 247 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 245 def hiera_v3_merge_behavior? instance_variable_defined?(:@hiera_v3_merge_behavior) end |
#hiera_xxx_call? ⇒ Boolean
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.
Returns ‘true` if the invocation stems from the hiera_xxx function family.
236 237 238 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 236 def hiera_xxx_call? instance_variable_defined?(:@hiera_xxx_call) end |
#lookup(key, module_name = nil) ⇒ 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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 73 def lookup(key, module_name = nil) key = LookupKey.new(key) unless key.is_a?(LookupKey) @top_key = key @module_name = module_name.nil? ? key.module_name : module_name save_current = self.class.current if save_current.equal?(self) yield else begin self.class.current = self yield ensure self.class.current = save_current end end end |
#lookup_adapter ⇒ 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.
112 113 114 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 112 def lookup_adapter @adapter ||= @adapter_class.adapt(scope.compiler) end |
#only_explain_options? ⇒ Boolean
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.
162 163 164 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 162 def @explainer.nil? ? false : @explainer. end |
#remember_scope_lookup(*lookup_result) ⇒ 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.
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
121 122 123 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 121 def remember_scope_lookup(*lookup_result) # Does nothing by default end |
#report_found(key, value) ⇒ 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.
180 181 182 183 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 180 def report_found(key, value) @explainer.accept_found(key, value) unless @explainer.nil? value end |
#report_found_in_defaults(key, value) ⇒ 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.
175 176 177 178 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 175 def report_found_in_defaults(key, value) @explainer.accept_found_in_defaults(key, value) unless @explainer.nil? value end |
#report_found_in_overrides(key, value) ⇒ 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.
170 171 172 173 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 170 def report_found_in_overrides(key, value) @explainer.accept_found_in_overrides(key, value) unless @explainer.nil? value end |
#report_location_not_found ⇒ 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.
201 202 203 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 201 def report_location_not_found @explainer.accept_location_not_found unless @explainer.nil? end |
#report_merge_source(merge_source) ⇒ 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.
185 186 187 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 185 def report_merge_source(merge_source) @explainer.accept_merge_source(merge_source) unless @explainer.nil? end |
#report_module_not_found(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.
205 206 207 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 205 def report_module_not_found(module_name) @explainer.accept_module_not_found(module_name) unless @explainer.nil? end |
#report_module_provider_not_found(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.
209 210 211 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 209 def report_module_provider_not_found(module_name) @explainer.accept_module_provider_not_found(module_name) unless @explainer.nil? end |
#report_not_found(key) ⇒ 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.
197 198 199 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 197 def report_not_found(key) @explainer.accept_not_found(key) unless @explainer.nil? end |
#report_result(value) ⇒ 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.
Report the result of a merge or fully resolved interpolated string
192 193 194 195 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 192 def report_result(value) @explainer.accept_result(value) unless @explainer.nil? value end |
#report_text(&block) ⇒ 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.
213 214 215 216 217 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 213 def report_text(&block) unless @explainer.nil? @explainer.accept_text(block.call) end end |
#set_global_only ⇒ Invocation
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.
Instructs the lookup framework to only perform lookups in the global layer
225 226 227 228 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 225 def set_global_only @global_only = true self end |
#set_hiera_v3_location_overrides(overrides) ⇒ 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.
Overrides passed from hiera_xxx functions down to V3DataHashFunctionProvider
254 255 256 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 254 def set_hiera_v3_location_overrides(overrides) @hiera_v3_location_overrides = [overrides].flatten unless overrides.nil? end |
#set_hiera_v3_merge_behavior ⇒ 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.
249 250 251 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 249 def set_hiera_v3_merge_behavior @hiera_v3_merge_behavior = true end |
#set_hiera_xxx_call ⇒ 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.
240 241 242 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 240 def set_hiera_xxx_call @hiera_xxx_call = true end |
#with(qualifier_type, qualifier) ⇒ 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.
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
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 135 def with(qualifier_type, qualifier) if explainer.nil? yield else @explainer.push(qualifier_type, qualifier) begin yield ensure @explainer.pop end end end |
#with_scope(scope) {|Invocation.new(scope, override_values, default_values, explainer)| ... } ⇒ Invocation
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.
Creates a new instance with same settings as this instance but with a new given scope and yields with that scope.
25 26 27 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 25 def with_scope(scope) yield(Invocation.new(scope, override_values, default_values, explainer)) end |
#without_explain ⇒ 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.
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/puppet/pops/lookup/invocation.rb', line 148 def without_explain if explainer.nil? yield else save_explainer = @explainer begin @explainer = nil yield ensure @explainer = save_explainer end end end |