Class: ChaosDetector::Stacker::FrameStack
- Inherits:
-
Object
- Object
- ChaosDetector::Stacker::FrameStack
- Defined in:
- lib/chaos_detector/stacker/frame_stack.rb
Instance Method Summary collapse
- #depth ⇒ Object
-
#initialize ⇒ FrameStack
constructor
A new instance of FrameStack.
- #inspect ⇒ Object
- #log(msg, **opts) ⇒ Object
- #peek ⇒ Object
- #pop(frame) ⇒ Object
- #push(frame) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ FrameStack
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
#depth ⇒ Object
17 18 19 |
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 17 def depth @stack.length end |
#inspect ⇒ Object
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 |
#peek ⇒ Object
21 22 23 |
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 21 def peek @stack.first end |
#pop(frame) ⇒ Object
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_s ⇒ Object
52 53 54 |
# File 'lib/chaos_detector/stacker/frame_stack.rb', line 52 def to_s 'Frames: %d' % depth end |