Sha256: 1f2a74522749766faafcad4f907e19c1478b07376f0e2eb8d4589fde64329453

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

module PryMoves::TracedMethod

  private

  def set_traced_method(binding)
    @recursion_level = 0
    @c_stack_level = 0
    @stay_at_frame = nil # reset tracked digest

    method = find_method_definition binding
    if method
      source = method.source_location
      set_method({
                   file: source[0],
                   start: source[1],
                   name: method.name,
                   end: (source[1] + method.source.count("\n") - 1)
                 })
    else
      set_method({file: binding.eval('__FILE__')})
    end
  end

  def find_method_definition(binding)
    method_name, obj, line, file =
      binding.eval '[__method__, self, __LINE__, __FILE__]'
    return unless method_name

    method = obj.method(method_name)
    return method if method.source_location[0] == file

    # If found file was different - search definition at superclasses:
    obj.class.ancestors.each do |cls|
      if cls.instance_methods(false).include? method_name
        method = cls.instance_method method_name
        return method if method.source_location[0] == file
      end
    end

    pry_puts "⚠️  Unable to find definition for method #{method_name} in #{obj}"

    nil
  end

  def set_method(method)
    #puts "set_traced_method #{method}"
    @method = method
  end

  def within_current_method?(file, line)
    @method[:file] == file and (
    @method[:start].nil? or
      line.between?(@method[:start], @method[:end])
    )
  end

  def before_end?(line)
    @method[:end] and line < @method[:end]
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pry-moves-0.1.13 lib/pry-moves/traced_method.rb
pry-moves-0.1.12 lib/pry-moves/traced_method.rb