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

binding_index[RW]

@return [Fixnum] The index of the active frame (binding) in the call-stack.

bindings[RW]

@return [Array<Binding>] The array of bindings that constitute

the call-stack.
prior_backtrace[R]

@return [Array] The backtrace of the Pry instance before the

FrameManager took over.
prior_binding[R]

@return [Binding] The binding of the Pry instance before the

FrameManager took over.
user[R]

@return [Hash] A hash for user defined data

Public Class Methods

new(bindings, _pry_) click to toggle source
# 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_frame_to(index, run_whereami=true) click to toggle source

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
current_frame() click to toggle source

@return [Binding] The currently active frame

# File lib/pry-stack_explorer/frame_manager.rb, line 55
def current_frame
  bindings[binding_index]
end
each(&block) click to toggle source

Iterate over all frames

# File lib/pry-stack_explorer/frame_manager.rb, line 44
def each(&block)
  bindings.each(&block)
end
filter_bindings(vapid_frames: false) click to toggle source
# 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
refresh_frame(run_whereami=true) click to toggle source

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_binding_index_safely(index) click to toggle source

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