Class: Byebug::PryProcessor
- Inherits:
-
Processor
- Object
- Processor
- Byebug::PryProcessor
- Defined in:
- lib/byebug/processors/pry_processor.rb
Overview
Extends raw byebug’s processor.
Instance Attribute Summary collapse
-
#pry ⇒ Object
Returns the value of attribute pry.
Instance Method Summary collapse
-
#at_breakpoint(_context, breakpoint) ⇒ Object
Called when a breakpoint is hit.
-
#at_line(context, _file, _line) ⇒ Object
Called when the wants to stop at a regular line.
-
#at_return(context, _file, _line) ⇒ Object
Called when the wants to stop right before a method return.
-
#initialize(interface = LocalInterface.new) ⇒ PryProcessor
constructor
A new instance of PryProcessor.
-
#perform(action, times) ⇒ Object
Set up a number of navigational commands to be performed by Byebug.
-
#run(&_block) ⇒ Object
Wrap a Pry REPL to catch navigational commands and act on them.
- #start ⇒ Object
Constructor Details
#initialize(interface = LocalInterface.new) ⇒ PryProcessor
Returns a new instance of PryProcessor.
11 12 13 14 15 |
# File 'lib/byebug/processors/pry_processor.rb', line 11 def initialize(interface = LocalInterface.new) super(interface) Byebug.handler = self end |
Instance Attribute Details
#pry ⇒ Object
Returns the value of attribute pry.
9 10 11 |
# File 'lib/byebug/processors/pry_processor.rb', line 9 def pry @pry end |
Instance Method Details
#at_breakpoint(_context, 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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/byebug/processors/pry_processor.rb', line 76 def at_breakpoint(_context, breakpoint) @pry ||= Pry.new brkpt_num = "\n Breakpoint #{breakpoint.id}. " @pry.output.print Pry::Helpers::Text.bold(brkpt_num) n_hits = breakpoint.hit_count @pry.output.puts(n_hits == 1 ? 'First hit' : "Hit #{n_hits} times.") expr = breakpoint.expr return unless expr @pry.output.print Pry::Helpers::Text.bold('Condition: ') @pry.output.puts expr end |
#at_line(context, _file, _line) ⇒ Object
Called when the wants to stop at a regular line
60 61 62 |
# File 'lib/byebug/processors/pry_processor.rb', line 60 def at_line(context, _file, _line) resume_pry(context) end |
#at_return(context, _file, _line) ⇒ Object
Called when the wants to stop right before a method return
67 68 69 |
# File 'lib/byebug/processors/pry_processor.rb', line 67 def at_return(context, _file, _line) resume_pry(context) end |
#perform(action, times) ⇒ Object
Set up a number of navigational commands to be performed by Byebug.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/byebug/processors/pry_processor.rb', line 44 def perform(action, times) case action when :next Byebug.current_context.step_over(times, 0) when :step Byebug.current_context.step_into(times) when :finish Byebug.current_context.step_out(times) end end |
#run(&_block) ⇒ Object
Wrap a Pry REPL to catch navigational commands and act on them.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/byebug/processors/pry_processor.rb', line 25 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[:times] || '1').to_i) return_value end |