Sha256: 563a1b908e3cd68b4aca0c0fc50bedc7dac951e6109ad22a1aa7b0d23b5dc385
Contents?: true
Size: 1.78 KB
Versions: 6
Compression:
Stored size: 1.78 KB
Contents
module PryStackExplorer class FrameManager include Enumerable attr_accessor :binding_index attr_accessor :bindings # @return [Hash] A hash for user defined data attr_reader :user def initialize(bindings, _pry_) self.bindings = bindings self.binding_index = 0 @pry = _pry_ @user = {} end # Iterate over all frames def each(&block) bindings.each(&block) end # Return a description of the frame (binding) # @param [Binding] b The binding. # @return [String] A description of the frame (binding). def frame_info_for(b) b_self = b.eval('self') b_method = b.eval('__method__') if b_method && b_method != :__binding__ && b_method != :__binding_impl__ b_method.to_s elsif b_self.instance_of?(Module) "<module:#{b_self}>" elsif b_self.instance_of?(Class) "<class:#{b_self}>" else "<main>" end end # Ensure the Pry instance's active binding is the frame manager's # active binding. def refresh_frame change_frame_to binding_index end # @return [Binding] The currently active frame def current_frame bindings[binding_index] end # Change active frame to the one indexed by `index`. # Note that indexing base is `0` # @param [Fixnum] index The index of the frame. def change_frame_to(index) if index > bindings.size - 1 @pry.output.puts "Warning: At top of stack, cannot go further!" elsif index < 0 @pry.output.puts "Warning: At bottom of stack, cannot go further!" else self.binding_index = index @pry.binding_stack[-1] = bindings[binding_index] @pry.run_command "whereami" end end end end
Version data entries
6 entries across 6 versions & 1 rubygems