Class: ChaosDetector::Stacker::FrameStack

Inherits:
Object
  • Object
show all
Defined in:
lib/chaos_detector/stacker/frame_stack.rb

Instance Method Summary collapse

Constructor Details

#initializeFrameStack

Returns a new instance of FrameStack.



8
9
10
11
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 8

def initialize
  @methods = []
  @modules = []
end

Instance Method Details

#depthObject



17
18
19
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 17

def depth
  @stack.length
end

#inspectObject



56
57
58
59
60
# 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) ⇒ Object



13
14
15
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 13

def log(msg, **opts)
  ChaosUtils.log_msg(msg, subject: 'FrameStack', **opts)
end

#peekObject



21
22
23
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 21

def peek
  @stack.first
end

#pop(frame) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object



48
49
50
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 48

def push(frame)
  @stack.unshift(frame)
end

#to_sObject



52
53
54
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 52

def to_s
  'Frames: %d' % depth
end