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
- ._ptype ⇒ Object
-
.from_asserted_args(environment_name, 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
Constructor Details
#initialize(function_context, lookup_invocation) ⇒ Context
Returns a new instance of Context.
107 108 109 110 |
# File 'lib/puppet/pops/lookup/context.rb', line 107 def initialize(function_context, lookup_invocation) @lookup_invocation = lookup_invocation @function_context = function_context end |
Class Method Details
._ptype ⇒ Object
67 68 69 |
# File 'lib/puppet/pops/lookup/context.rb', line 67 def self._ptype @type end |
.from_asserted_args(environment_name, 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.
100 101 102 |
# File 'lib/puppet/pops/lookup/context.rb', line 100 def self.from_asserted_args(environment_name, module_name) new(FunctionContext.new(environment_name, module_name, nil), Invocation.current) end |
.register_ptype(loader, ir) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/puppet/pops/lookup/context.rb', line 71 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::PStringType::NON_EMPTY, 'module_name' => { Types::KEY_TYPE => tf.optional(Types::PStringType::NON_EMPTY), Types::KEY_VALUE => nil } }, { '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]))) ) } ).resolve(Types::TypeParser.singleton, loader) end |
Instance Method Details
#explain(&block) ⇒ Object
Will call the given block to obtain a textual explanation if explanation support is active.
114 115 116 117 |
# File 'lib/puppet/pops/lookup/context.rb', line 114 def explain(&block) @lookup_invocation.report_text(&block) nil end |
#interpolate(value) ⇒ Object
Resolve interpolation expressions in the given value
122 123 124 |
# File 'lib/puppet/pops/lookup/context.rb', line 122 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.
131 132 133 |
# File 'lib/puppet/pops/lookup/context.rb', line 131 def invocation @lookup_invocation end |
#not_found ⇒ Object
126 127 128 |
# File 'lib/puppet/pops/lookup/context.rb', line 126 def not_found throw :no_such_key end |