Class: Puppet::Pops::Lookup::Context
- Extended by:
- Forwardable
- Includes:
- Types::PuppetObject
- Defined in:
- lib/puppet/pops/lookup/context.rb
Overview
The Context is created once for each call to a function. It provides a combination of the Invocation object needed to provide explanation support and the FunctionContext object needed to provide the private cache. The Context is part of the public API. It will be passed to a data_hash, data_dig, or lookup_key function and its attributes and methods can be used in a Puppet function as well as in a Ruby function. The Context is maps to the Pcore type ‘Puppet::LookupContext’
Class Method Summary collapse
- ._pcore_type ⇒ Object
-
.from_asserted_args(module_name) ⇒ Object
Mainly for test purposes.
- .register_ptype(loader, ir) ⇒ Object
Instance Method Summary collapse
-
#explain(&block) ⇒ Object
Will call the given block to obtain a textual explanation if explanation support is active.
-
#initialize(function_context, lookup_invocation) ⇒ Context
constructor
A new instance of Context.
-
#interpolate(value) ⇒ Object
Resolve interpolation expressions in the given value.
- #invocation ⇒ Object private
- #not_found ⇒ Object
Methods included from Types::PuppetObject
#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type
Constructor Details
#initialize(function_context, lookup_invocation) ⇒ Context
Returns a new instance of Context.
171 172 173 174 |
# File 'lib/puppet/pops/lookup/context.rb', line 171 def initialize(function_context, lookup_invocation) @lookup_invocation = lookup_invocation @function_context = function_context end |
Class Method Details
._pcore_type ⇒ Object
129 130 131 |
# File 'lib/puppet/pops/lookup/context.rb', line 129 def self._pcore_type @type end |
.from_asserted_args(module_name) ⇒ Object
Mainly for test purposes. Makes it possible to create a Puppet::Pops::Lookup::Context in Puppet code provided that a current Invocation exists.
164 165 166 |
# File 'lib/puppet/pops/lookup/context.rb', line 164 def self.from_asserted_args(module_name) new(FunctionContext.new(EnvironmentContext.adapt(Puppet.lookup(:environments).get(Puppet[:environment])), module_name, nil), Invocation.current) end |
.register_ptype(loader, ir) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/puppet/pops/lookup/context.rb', line 133 def self.register_ptype(loader, ir) tf = Types::TypeFactory key_type = tf.optional(tf.scalar) @type = Pcore::create_object_type(loader, ir, self, 'Puppet::LookupContext', 'Any', { 'environment_name' => { Types::KEY_TYPE => Types::PStringType::NON_EMPTY, Types::KEY_KIND => Types::PObjectType::ATTRIBUTE_KIND_DERIVED }, 'module_name' => { Types::KEY_TYPE => tf.variant(Types::PStringType::NON_EMPTY, Types::PUndefType::DEFAULT) } }, { 'not_found' => tf.callable([0, 0], tf.undef), 'explain' => tf.callable([0, 0, tf.callable(0,0)], tf.undef), 'interpolate' => tf.callable(1, 1), 'cache' => tf.callable([key_type, tf.any], tf.any), 'cache_all' => tf.callable([tf.hash_kv(key_type, tf.any)], tf.undef), 'cache_has_key' => tf.callable([key_type], tf.boolean), 'cached_value' => tf.callable([key_type], tf.any), 'cached_entries' => tf.variant( tf.callable([0, 0, tf.callable(1,1)], tf.undef), tf.callable([0, 0, tf.callable(2,2)], tf.undef), tf.callable([0, 0], tf.iterable(tf.tuple([key_type, tf.any])))), 'cached_file_data' => tf.callable(tf.string, tf.optional(tf.callable([1, 1]))) } ).resolve(loader) end |
Instance Method Details
#explain(&block) ⇒ Object
Will call the given block to obtain a textual explanation if explanation support is active.
178 179 180 181 |
# File 'lib/puppet/pops/lookup/context.rb', line 178 def explain(&block) @lookup_invocation.report_text(&block) nil end |
#interpolate(value) ⇒ Object
Resolve interpolation expressions in the given value
186 187 188 |
# File 'lib/puppet/pops/lookup/context.rb', line 186 def interpolate(value) @function_context.interpolate(value, @lookup_invocation, true) end |
#invocation ⇒ 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.
195 196 197 |
# File 'lib/puppet/pops/lookup/context.rb', line 195 def invocation @lookup_invocation end |
#not_found ⇒ Object
190 191 192 |
# File 'lib/puppet/pops/lookup/context.rb', line 190 def not_found throw :no_such_key end |