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.

API:

  • private

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.

API:

  • private



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

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.

API:

  • private



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

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.

API:

  • private



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

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