Class: Byebug::PryProcessor

Inherits:
CommandProcessor
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/byebug/processors/pry_processor.rb

Overview

Extends raw byebug’s processor.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pryObject

Returns the value of attribute pry.



10
11
12
# File 'lib/byebug/processors/pry_processor.rb', line 10

def pry
  @pry
end

Class Method Details

.startObject



16
17
18
19
20
21
# File 'lib/byebug/processors/pry_processor.rb', line 16

def self.start
  Byebug.start
  Setting[:autolist] = false
  Context.processor = self
  Byebug.current_context.step_out(5, true)
end

Instance Method Details

#at_breakpoint(breakpoint) ⇒ Object

Called when a breakpoint is hit. Note that ‘at_line“ is called inmediately after with the context’s ‘stop_reason == :breakpoint`, so we must not resume the pry instance here



80
81
82
83
84
85
86
87
88
89
# File 'lib/byebug/processors/pry_processor.rb', line 80

def at_breakpoint(breakpoint)
  @pry ||= Pry.new

  output.puts bold("\n  Breakpoint #{breakpoint.id}. ") + n_hits(breakpoint)

  expr = breakpoint.expr
  return unless expr

  output.puts bold("Condition: ") + expr
end

#at_lineObject

Called when the debugger wants to stop at a regular line



64
65
66
# File 'lib/byebug/processors/pry_processor.rb', line 64

def at_line
  resume_pry
end

#at_return(_return_value) ⇒ Object

Called when the debugger wants to stop right before a method return



71
72
73
# File 'lib/byebug/processors/pry_processor.rb', line 71

def at_return(_return_value)
  resume_pry
end

#perform(action, options = {}) ⇒ Object

Set up a number of navigational commands to be performed by Byebug.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/byebug/processors/pry_processor.rb', line 45

def perform(action, options = {})
  return unless %i[
    backtrace
    down
    finish
    frame
    next
    step
    up
  ].include?(action)

  send("perform_#{action}", options)
end

#run(&_block) ⇒ Object

Wrap a Pry REPL to catch navigational commands and act on them.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/byebug/processors/pry_processor.rb', line 26

def run(&_block)
  return_value = nil

  command = catch(:breakout_nav) do # Throws from PryByebug::Commands
    return_value = allowing_other_threads { yield }
    {} # Nothing thrown == no navigational command
  end

  # Pry instance to resume after stepping
  @pry = command[:pry]

  perform(command[:action], command[:options])

  return_value
end