class ChaosDetector::Stacker::FrameStack

Public Class Methods

new() click to toggle source
# File lib/chaos_detector/stacker/frame_stack.rb, line 8
def initialize
  @methods = []
  @modules = []
end

Public Instance Methods

depth() click to toggle source
# File lib/chaos_detector/stacker/frame_stack.rb, line 17
def depth
  @stack.length
end
inspect() click to toggle source
# File lib/chaos_detector/stacker/frame_stack.rb, line 56
def inspect
  msg = "#{self}\n"
  msg << ChaosUtils.decorate_tuple(@stack.map { |f| f.to_s}, join_str: " -> \n", indent_length: 2, clamp: :none)
  msg
end
log(msg, **opts) click to toggle source
# File lib/chaos_detector/stacker/frame_stack.rb, line 13
def log(msg, **opts)
  ChaosUtils.log_msg(msg, subject: 'FrameStack', **opts)
end
peek() click to toggle source
# File lib/chaos_detector/stacker/frame_stack.rb, line 21
def peek
  @stack.first
end
pop(frame) click to toggle source
# File lib/chaos_detector/stacker/frame_stack.rb, line 25
def pop(frame)
  raise ArgumentError, 'Current Frame is required' if frame.nil?

  popped_frame, n_frame = @stack.each_with_index.find do |f, n|
    if f == frame
      true
    elsif n.zero? && frame.fn_name == f.fn_name
      # log("Matching #{f} \nto:\n #{frame} as most recent entry in stack.")
      true
    else
      false
    end
  end

  # if n_frame.nil?
  #   log("Could not find #{frame} in stack")
  #   log(self.inspect)
  # end

  @stack.slice!(0..n_frame) unless n_frame.nil?
  [popped_frame, n_frame]
end
push(frame) click to toggle source
# File lib/chaos_detector/stacker/frame_stack.rb, line 48
def push(frame)
  @stack.unshift(frame)
end
to_s() click to toggle source
# File lib/chaos_detector/stacker/frame_stack.rb, line 52
def to_s
  'Frames: %d' % depth
end