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
149 def initialize(parent, bindings, description = '')
150   @parent = parent
151   @bindings = parent.bindings.merge(bindings || {})
152   @description = description
153 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
161 def lookup(name, &block)
162   if @bindings.include?(name)
163     value = @bindings[name]
164     value.is_a?(Proc) ? (@bindings[name] = value.call) : value
165   elsif block
166     block.call
167   else
168     raise UndefinedBindingError,
169           _("Unable to lookup '%{name}'") % { name: name }
170   end
171 end
pop() click to toggle source

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

@api private

    # File lib/puppet/context.rb
176 def pop
177   @parent
178 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
184 def push(overrides, description = '')
185   Puppet::Context::Stack.new(self, overrides, description)
186 end