Module: Puppet::Pops::PuppetStack Private

Defined in:
lib/puppet/pops/puppet_stack.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Utility class for keeping track of the “Puppet stack”, ie the file and line numbers of Puppet Code that created the current context.

To use this make a call with:

“`rb Puppet::Pops::PuppetStack.stack(file, line, receiver, message, args) “`

To get the stack call:

“`rb Puppet::Pops::PuppetStack.stacktrace “`

or

“`rb Puppet::Pops::PuppetStack.top_of_stack “`

To support testing, a given file that is an empty string, or nil as well as a nil line number are supported. Such stack frames will be represented with the text `unknown` and `0´ respectively.

Class Method Summary collapse

Class Method Details

.stack(file, line, obj, message, args, &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.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/puppet/pops/puppet_stack.rb', line 32

def self.stack(file, line, obj, message, args, &block)
  file = 'unknown' if (file.nil? || file == '')
  line = 0 if line.nil?

  result = nil
  @stack.value.unshift([file, line])
  begin
    if block_given?
      result = obj.send(message, *args, &block)
    else
      result = obj.send(message, *args)
    end
  ensure
    @stack.value.shift()
  end
  result
end

.stacktraceObject

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.


50
51
52
# File 'lib/puppet/pops/puppet_stack.rb', line 50

def self.stacktrace
  @stack.value.dup
end

.top_of_stackObject

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 an Array with the top of the puppet stack, or an empty Array if there was no such entry.


56
57
58
# File 'lib/puppet/pops/puppet_stack.rb', line 56

def self.top_of_stack
  @stack.value.first || []
end