class PryStackExplorer::FrameManager
This class represents a call-stack. It stores the frames that make up the stack and is responsible for updating the associated Pry
instance to reflect the active frame. It is fully Enumerable.
Attributes
@return [Fixnum] The index of the active frame (binding) in the call-stack.
@return [Array<Binding>] The array of bindings that constitute
the call-stack.
@return [Array] The backtrace of the Pry
instance before the
FrameManager took over.
@return [Binding] The binding of the Pry
instance before the
FrameManager took over.
@return [Hash] A hash for user defined data
Public Class Methods
# File lib/pry-stack_explorer/frame_manager.rb, line 27 def initialize(bindings, _pry_) self.bindings = bindings self.binding_index = 0 @pry = _pry_ @user = {} @prior_binding = _pry_.binding_stack.last @prior_backtrace = _pry_.backtrace end
Public Instance Methods
Change active frame to the one indexed by `index`. Note that indexing base is `0` @param [Fixnum] index The index of the frame.
# File lib/pry-stack_explorer/frame_manager.rb, line 75 def change_frame_to(index, run_whereami=true) set_binding_index_safely(index) if @pry.binding_stack.empty? @pry.binding_stack.replace [bindings[binding_index]] else @pry.binding_stack[-1] = bindings[binding_index] end @pry.run_command "whereami" if run_whereami end
@return [Binding] The currently active frame
# File lib/pry-stack_explorer/frame_manager.rb, line 55 def current_frame bindings[binding_index] end
Iterate over all frames
# File lib/pry-stack_explorer/frame_manager.rb, line 44 def each(&block) bindings.each(&block) end
# File lib/pry-stack_explorer/frame_manager.rb, line 36 def filter_bindings(vapid_frames: false) bindings.reject do |binding| !vapid_frames and binding.local_variable_defined?(:vapid_frame) end end
Ensure the Pry
instance's active binding is the frame manager's active binding.
# File lib/pry-stack_explorer/frame_manager.rb, line 50 def refresh_frame(run_whereami=true) change_frame_to binding_index, run_whereami end
Set the binding index (aka frame index), but raising an Exception when invalid index received. Also converts negative indices to their positive counterparts. @param [Fixnum] index The index.
# File lib/pry-stack_explorer/frame_manager.rb, line 62 def set_binding_index_safely(index) if index > bindings.size - 1 raise Pry::CommandError, "At top of stack, cannot go further" elsif index < 0 raise Pry::CommandError, "At bottom of stack, cannot go further" else self.binding_index = index end end