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.



8
9
10
# File 'lib/byebug/processors/pry_processor.rb', line 8

def pry
  @pry
end

Class Method Details

.startObject



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

def self.start
  Byebug.start
  Setting[:autolist] = false
  Context.processor = self
  Byebug.current_context.step_out(4, 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



86
87
88
89
90
91
92
93
94
95
# File 'lib/byebug/processors/pry_processor.rb', line 86

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_endObject

Called when the debugger wants to stop right before the end of a class definition



77
78
79
# File 'lib/byebug/processors/pry_processor.rb', line 77

def at_end
  resume_pry
end

#at_lineObject

Called when the debugger wants to stop at a regular line



62
63
64
# File 'lib/byebug/processors/pry_processor.rb', line 62

def at_line
  resume_pry
end

#at_return(_return_value) ⇒ Object

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



69
70
71
# File 'lib/byebug/processors/pry_processor.rb', line 69

def at_return(_return_value)
  resume_pry
end

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

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



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

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.



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

def run(&_block)
  return_value = nil

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

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

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

  return_value
end