module PryStack::FrameHelpers

Private Instance Methods

find_frame_by_block(up_or_down) { |b| ... } click to toggle source
# File lib/pry-stack/commands.rb, line 115
def find_frame_by_block(up_or_down)
  start_index = frame_manager.binding_index

  if up_or_down == :down
    enum = 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_index = frame_manager.bindings.index(new_frame)
end
find_frame_by_object_regex(class_regex, method_regex, up_or_down) click to toggle source
# File lib/pry-stack/commands.rb, line 100
def find_frame_by_object_regex(class_regex, method_regex, up_or_down)
  frame_index = find_frame_by_block(up_or_down) do |b|
    class_match = b.eval("self.class").to_s =~ class_regex
    meth_match = b.eval("__method__").to_s =~ method_regex

    class_match && meth_match
  end

  if frame_index
    frame_index
  else
    raise Pry::CommandError, "No frame that matches #{class_regex.source}" + '#' + "#{method_regex.source} found!"
  end
end
find_frame_by_regex(regex, up_or_down) click to toggle source

Regexp.new(args)

# File lib/pry-stack/commands.rb, line 88
def find_frame_by_regex(regex, up_or_down)
  frame_index = find_frame_by_block(up_or_down) do |b|
    b.eval("__method__").to_s =~ regex
  end

  if frame_index
    frame_index
  else
    raise Pry::CommandError, "No frame that matches #{regex.source} found!"
  end
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/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/commands.rb, line 48
def frame_info(b, verbose = false)
  meth = b.eval('__method__')
  b_self = b.eval('self')
  meth_obj = Pry::Method.from_binding(b) if meth

  type = b.frame_type ? "[#{b.frame_type}]".ljust(9) : ""
  desc = b.frame_description ? "#{b.frame_description}" : "#{frame_description(b)}"
  sig = meth_obj ? "<#{signature_with_owner(meth_obj)}>" : ""

  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 [PryStack::FrameManager] The active frame manager for

the current `Pry` instance.
# File lib/pry-stack/commands.rb, line 7
def frame_manager
  PryStack.frame_manager(_pry_)
end
frame_managers() click to toggle source

@return [Array<PryStack::FrameManager>] All the frame

managers for the current `Pry` instance.
# File lib/pry-stack/commands.rb, line 13
def frame_managers
  PryStack.frame_managers(_pry_)
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/commands.rb, line 19
def prior_context_exists?
  frame_managers.count > 1 || frame_manager.prior_binding
end
signature_with_owner(meth_obj) click to toggle source

@param [Pry::Method] meth_obj The method object. @return [String] Signature for the method object in Class#method format.

# File lib/pry-stack/commands.rb, line 69
def signature_with_owner(meth_obj)
  if !meth_obj.undefined?
    args = meth_obj.parameters.inject([]) do |arr, (type, name)|
      name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
      arr << case type
             when :req   then name.to_s
             when :opt   then "#{name}=?"
             when :rest  then "*#{name}"
             when :block then "&#{name}"
             else '?'
             end
    end
    "#{meth_obj.name_with_owner}(#{args.join(', ')})"
  else
    "#{meth_obj.name_with_owner}(UNKNOWN) (undefined method)"
  end
end