class Puppet::Context::Stack

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.

@api private

Attributes

bindings[R]

Public Class Methods

new(parent, bindings, description = '') click to toggle source
    # File lib/puppet/context.rb
150 def initialize(parent, bindings, description = '')
151   @parent = parent
152   @bindings = parent.bindings.merge(bindings || {})
153   @description = description
154 end

Public Instance Methods

lookup(name, &block) click to toggle source

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.

@api private

    # File lib/puppet/context.rb
162 def lookup(name, &block)
163   if @bindings.include?(name)
164     value = @bindings[name]
165     value.is_a?(Proc) ? (@bindings[name] = value.call) : value
166   elsif block
167     block.call
168   else
169     raise UndefinedBindingError,
170           _("Unable to lookup '%{name}'") % { name: name }
171   end
172 end
pop() click to toggle source

Pop one level off the stack by returning the parent object.

@api private

    # File lib/puppet/context.rb
177 def pop
178   @parent
179 end
push(overrides, description = '') click to toggle source

Push bindings onto the stack by creating a new Stack object with `self` as the parent

@api private

    # File lib/puppet/context.rb
185 def push(overrides, description = '')
186   Puppet::Context::Stack.new(self, overrides, description)
187 end