module PryStackExplorer::FrameHelpers
Private Instance Methods
find_frame_by_block(up_or_down) { |b| ... }
click to toggle source
# File lib/pry-stack_explorer/commands.rb, line 73 def find_frame_by_block(up_or_down) start_index = frame_manager.binding_index if up_or_down == :down enum = start_index == 0 ? [].each : frame_manager.bindings[0..start_index - 1].reverse_each else enum = frame_manager.bindings[start_index + 1..-1] end new_frame = enum.find do |b| yield(b) end frame_manager.bindings.index(new_frame) end
find_frame_by_direction(up_or_down, step_into_vapid: false)
click to toggle source
# File lib/pry-stack_explorer/commands.rb, line 90 def find_frame_by_direction(up_or_down, step_into_vapid: false) frame_index = find_frame_by_block(up_or_down) do |b| step_into_vapid or not b.local_variable_defined?(:vapid_frame) end frame_index || raise(Pry::CommandError, "At #{up_or_down == :up ? 'top' : 'bottom'} of stack, cannot go further") end
find_frame_by_regex(regex, up_or_down)
click to toggle source
# File lib/pry-stack_explorer/commands.rb, line 64 def find_frame_by_regex(regex, up_or_down) frame_index = find_frame_by_block(up_or_down) do |b| (b.eval('"#{__FILE__}:#{__LINE__}"') =~ regex) or (b.eval("__method__").to_s =~ regex) end frame_index || raise(Pry::CommandError, "No frame that matches #{regex.source} found") end
frame_description(b)
click to toggle source
Return a description of the frame (binding). This is only useful for regular old bindings that have not been enhanced by `#of_caller`. @param [Binding] b The binding. @return [String] A description of the frame (binding).
# File lib/pry-stack_explorer/commands.rb, line 28 def frame_description(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
frame_info(b, verbose = false)
click to toggle source
Return a description of the passed binding object. Accepts an optional `verbose` parameter. @param [Binding] b The binding. @param [Boolean] verbose Whether to generate a verbose description. @return [String] The description of the binding.
# File lib/pry-stack_explorer/commands.rb, line 48 def frame_info(b, verbose = false) b_self = b.eval('self') type = b.frame_type ? "[#{b.frame_type}]".ljust(9) : "" desc = b.frame_description ? "#{b.frame_description}" : "#{frame_description(b)}" sig = PryMoves::Helpers.method_signature_with_owner b self_clipped = "#{Pry.view_clip(b_self)}" path = "@ #{b.eval('__FILE__')}:#{b.eval('__LINE__')}" if !verbose "#{type} #{desc} #{sig}" else "#{type} #{desc} #{sig}\n in #{self_clipped} #{path}" end end
frame_manager()
click to toggle source
@return [PryStackExplorer::FrameManager] The active frame manager for
the current `Pry` instance.
# File lib/pry-stack_explorer/commands.rb, line 7 def frame_manager PryStackExplorer.frame_manager(_pry_) end
frame_managers()
click to toggle source
@return [Array<PryStackExplorer::FrameManager>] All the frame
managers for the current `Pry` instance.
# File lib/pry-stack_explorer/commands.rb, line 13 def frame_managers PryStackExplorer.frame_managers(_pry_) end
move(direction, param)
click to toggle source
# File lib/pry-stack_explorer/commands.rb, line 100 def move(direction, param) raise Pry::CommandError, "Nowhere to go" unless frame_manager if param == '+' or param.nil? index = find_frame_by_direction direction, step_into_vapid: param == '+' frame_manager.change_frame_to index else index = find_frame_by_regex(Regexp.new(param), direction) frame_manager.change_frame_to index end end
prior_context_exists?()
click to toggle source
@return [Boolean] Whether there is a context to return to once
the current `frame_manager` is popped.
# File lib/pry-stack_explorer/commands.rb, line 19 def prior_context_exists? frame_managers.count > 1 || frame_manager.prior_binding end