Class: PryStackExplorer::FrameManager
- Inherits:
-
Object
- Object
- PryStackExplorer::FrameManager
- Includes:
- Enumerable
- Defined in:
- lib/pry-stack_explorer/frame_manager.rb
Overview
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.
Instance Attribute Summary (collapse)
-
- (Fixnum) binding_index
The index of the active frame (binding) in the call-stack.
-
- (Array<Binding>) bindings
The array of bindings that constitute the call-stack.
-
- (Array) prior_backtrace
readonly
The backtrace of the Pry instance before the FrameManager took over.
-
- (Binding) prior_binding
readonly
The binding of the Pry instance before the FrameManager took over.
-
- (Hash) user
readonly
A hash for user defined data.
Instance Method Summary (collapse)
-
- (Object) change_frame_to(index, run_whereami = true)
Change active frame to the one indexed by
index. -
- (Binding) current_frame
The currently active frame.
-
- (Object) each(&block)
Iterate over all frames.
-
- (FrameManager) initialize(bindings, _pry_)
constructor
A new instance of FrameManager.
-
- (Object) refresh_frame(run_whereami = true)
Ensure the Pry instance's active binding is the frame manager's active binding.
-
- (Object) set_binding_index_safely(index)
Set the binding index (aka frame index), but raising an Exception when invalid index received.
Constructor Details
- (FrameManager) initialize(bindings, _pry_)
A new instance of FrameManager
27 28 29 30 31 32 33 34 |
# 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 |
Instance Attribute Details
- (Fixnum) binding_index
The index of the active frame (binding) in the call-stack.
14 15 16 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 14 def binding_index @binding_index end |
- (Array<Binding>) bindings
The array of bindings that constitute the call-stack.
11 12 13 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 11 def bindings @bindings end |
- (Array) prior_backtrace (readonly)
The backtrace of the Pry instance before the FrameManager took over.
25 26 27 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 25 def prior_backtrace @prior_backtrace end |
- (Binding) prior_binding (readonly)
The binding of the Pry instance before the FrameManager took over.
21 22 23 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 21 def prior_binding @prior_binding end |
- (Hash) user (readonly)
A hash for user defined data
17 18 19 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 17 def user @user end |
Instance Method Details
- (Object) change_frame_to(index, run_whereami = true)
Change active frame to the one indexed by index.
Note that indexing base is 0
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 71 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 |
- (Binding) current_frame
The currently active frame
48 49 50 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 48 def current_frame bindings[binding_index] end |
- (Object) each(&block)
Iterate over all frames
37 38 39 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 37 def each(&block) bindings.each(&block) end |
- (Object) refresh_frame(run_whereami = true)
Ensure the Pry instance's active binding is the frame manager's active binding.
43 44 45 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 43 def refresh_frame(run_whereami=true) change_frame_to binding_index, run_whereami end |
- (Object) set_binding_index_safely(index)
Set the binding index (aka frame index), but raising an Exception when invalid index received. Also converts negative indices to their positive counterparts.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pry-stack_explorer/frame_manager.rb', line 55 def set_binding_index_safely(index) if index > bindings.size - 1 raise Pry::CommandError, "At top of stack, cannot go further!" elsif index < -bindings.size raise Pry::CommandError, "At bottom of stack, cannot go further!" else # wrap around negative indices index = (bindings.size - 1) + index + 1 if index < 0 self.binding_index = index end end |