module Puppet::Pops::PuppetStack
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.
Public Class Methods
stack(file, line, obj, message, args, &block)
click to toggle source
# File lib/puppet/pops/puppet_stack.rb 33 def self.stack(file, line, obj, message, args, &block) 34 file = 'unknown' if (file.nil? || file == '') 35 line = 0 if line.nil? 36 37 result = nil 38 @stack.value.unshift([file, line]) 39 begin 40 if block_given? 41 result = obj.send(message, *args, &block) 42 else 43 result = obj.send(message, *args) 44 end 45 ensure 46 @stack.value.shift() 47 end 48 result 49 end
stacktrace()
click to toggle source
# File lib/puppet/pops/puppet_stack.rb 51 def self.stacktrace 52 @stack.value.dup 53 end
top_of_stack()
click to toggle source
Returns an Array with the top of the puppet stack, or an empty Array if there was no such entry.
# File lib/puppet/pops/puppet_stack.rb 57 def self.top_of_stack 58 @stack.value.first || [] 59 end