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.



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

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.



52
53
54
# File 'lib/puppet/pops/puppet_stack.rb', line 52

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.



58
59
60
# File 'lib/puppet/pops/puppet_stack.rb', line 58

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