Sha256: 0e539c48fb6caee1d4074b7744c11fa7cabfe3ab5ead0fbb97031087746323df

Contents?: true

Size: 1.32 KB

Versions: 160

Compression:

Stored size: 1.32 KB

Contents

module Puppet::Pops
# Module for making a call such that there is an identifiable entry on
# the ruby call stack enabling getting a puppet call stack
# To use this make a call with:
# ```
# Puppet::Pops::PuppetStack.stack(file, line, receiver, message, args)
# ```
# To get the stack call:
# ```
# Puppet::Pops::PuppetStack.stacktrace
#
# When getting a backtrace in Ruby, the puppet stack frames are
# identified as coming from "in 'stack'" and having a ".pp" file
# name.
# 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.
#
module PuppetStack
  # Sends a message to an obj such that it appears to come from
  # file, line when calling stacktrace.
  #
  def self.stack(file, line, obj, message, args, &block)
    file = '' if file.nil?
    line = 0 if line.nil?

    if block_given?
      Kernel.eval("obj.send(message, *args, &block)", Kernel.binding(), file, line)
    else
      Kernel.eval("obj.send(message, *args)", Kernel.binding(), file, line)
    end
  end

  def self.stacktrace
    caller().reduce([]) do |memo, loc|
      if loc =~ /^(.*\.pp)?:([0-9]+):in (`stack'|`block in call_function')/
        memo << [$1.nil? ? 'unknown' : $1, $2.to_i]
      end
      memo
    end
  end
end
end

Version data entries

160 entries across 160 versions & 3 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/pops/puppet_stack.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/pops/puppet_stack.rb
puppet-5.3.7 lib/puppet/pops/puppet_stack.rb
puppet-5.3.7-x86-mingw32 lib/puppet/pops/puppet_stack.rb
puppet-5.3.7-x64-mingw32 lib/puppet/pops/puppet_stack.rb
puppet-5.3.7-universal-darwin lib/puppet/pops/puppet_stack.rb
puppet-4.10.12 lib/puppet/pops/puppet_stack.rb
puppet-4.10.12-x86-mingw32 lib/puppet/pops/puppet_stack.rb
puppet-4.10.12-x64-mingw32 lib/puppet/pops/puppet_stack.rb
puppet-4.10.12-universal-darwin lib/puppet/pops/puppet_stack.rb
bolt-0.20.3 vendored/puppet/lib/puppet/pops/puppet_stack.rb
bolt-0.20.2 vendored/puppet/lib/puppet/pops/puppet_stack.rb
bolt-0.19.1 vendored/puppet/lib/puppet/pops/puppet_stack.rb
puppet-4.10.11 lib/puppet/pops/puppet_stack.rb
puppet-4.10.11-x86-mingw32 lib/puppet/pops/puppet_stack.rb
puppet-4.10.11-x64-mingw32 lib/puppet/pops/puppet_stack.rb
puppet-4.10.11-universal-darwin lib/puppet/pops/puppet_stack.rb
puppet-5.3.6 lib/puppet/pops/puppet_stack.rb
puppet-5.3.6-x86-mingw32 lib/puppet/pops/puppet_stack.rb
puppet-5.3.6-x64-mingw32 lib/puppet/pops/puppet_stack.rb