Class: Puppet::Context::Stack Private
Overview
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.
Internal implementation of the bindings stack used by Puppet::Context. An instance of Puppet::Context::Stack represents one level of bindings. It caches a merged copy of all the bindings in the stack up to this point. Each element of the stack is immutable, allowing the base to be shared between threads.
Instance Attribute Summary collapse
- #bindings ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(parent, bindings, description = '') ⇒ Stack
constructor
private
A new instance of Stack.
-
#lookup(name, &block) ⇒ Object
private
Lookup a binding in the current stack.
-
#pop ⇒ Object
private
Pop one level off the stack by returning the parent object.
-
#push(overrides, description = '') ⇒ Object
private
Push bindings onto the stack by creating a new Stack object with ‘self` as the parent.
Constructor Details
#initialize(parent, bindings, description = '') ⇒ Stack
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 a new instance of Stack.
151 152 153 154 155 |
# File 'lib/puppet/context.rb', line 151 def initialize(parent, bindings, description = '') @parent = parent @bindings = parent.bindings.merge(bindings || {}) @description = description end |
Instance Attribute Details
#bindings ⇒ 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.
149 150 151 |
# File 'lib/puppet/context.rb', line 149 def bindings @bindings end |
Instance Method Details
#lookup(name, &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.
Lookup a binding in the current stack. Return the value if it is present. If the value is a stored Proc, evaluate, cache, and return the result. If no binding is found and a block is passed evaluate it and return the result. Otherwise an exception is raised.
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/puppet/context.rb', line 163 def lookup(name, &block) if @bindings.include?(name) value = @bindings[name] value.is_a?(Proc) ? (@bindings[name] = value.call) : value elsif block block.call else raise UndefinedBindingError, _("Unable to lookup '%{name}'") % { name: name } end end |
#pop ⇒ 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.
Pop one level off the stack by returning the parent object.
178 179 180 |
# File 'lib/puppet/context.rb', line 178 def pop @parent end |
#push(overrides, description = '') ⇒ 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.
Push bindings onto the stack by creating a new Stack object with ‘self` as the parent
186 187 188 |
# File 'lib/puppet/context.rb', line 186 def push(overrides, description = '') Puppet::Context::Stack.new(self, overrides, description) end |