Class: PryByebug::Processor
- Inherits:
-
Byebug::Processor
- Object
- Byebug::Processor
- PryByebug::Processor
- Defined in:
- lib/pry-byebug/processor.rb
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 triggered.
- #at_catchpoint(context, exception) ⇒ Object
-
#at_line(context, file, line) ⇒ Object
— Callbacks from byebug C extension —.
-
#debugging=(enabled) ⇒ Object
Adjust debugging.
-
#initialize(interface = Byebug::LocalInterface.new) ⇒ Processor
constructor
A new instance of Processor.
-
#run(initial = true, &block) ⇒ Object
Wrap a Pry REPL to catch navigational commands and act on them.
Constructor Details
#initialize(interface = Byebug::LocalInterface.new) ⇒ Processor
Returns a new instance of Processor.
8 9 10 11 12 13 14 |
# File 'lib/pry-byebug/processor.rb', line 8 def initialize(interface = Byebug::LocalInterface.new) super(interface) Byebug.handler = self @always_enabled = true @delayed = Hash.new(0) end |
Instance Attribute Details
#pry ⇒ Object
Returns the value of attribute pry.
6 7 8 |
# File 'lib/pry-byebug/processor.rb', line 6 def pry @pry end |
Instance Method Details
#at_breakpoint(context, breakpoint) ⇒ Object
Called when a breakpoint is triggered. Note: ‘at_line“ is called immediately after with the context’s ‘stop_reason == :breakpoint`.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pry-byebug/processor.rb', line 90 def at_breakpoint(context, breakpoint) @pry.output.print Pry::Helpers::Text.bold("\nBreakpoint #{breakpoint.id}. ") @pry.output.puts (breakpoint.hit_count == 1 ? 'First hit.' : "Hit #{breakpoint.hit_count} times." ) if (expr = breakpoint.expr) @pry.output.print Pry::Helpers::Text.bold("Condition: ") @pry.output.puts expr end end |
#at_catchpoint(context, exception) ⇒ Object
101 102 103 |
# File 'lib/pry-byebug/processor.rb', line 101 def at_catchpoint(context, exception) # TODO end |
#at_line(context, file, line) ⇒ Object
— Callbacks from byebug C extension —
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pry-byebug/processor.rb', line 69 def at_line(context, file, line) # If any delayed nexts/steps, do 'em. if @delayed[:next] > 1 context.step_over(@delayed[:next] - 1, 0) elsif @delayed[:step] > 1 context.step_into(@delayed[:step] - 1) elsif @delayed[:finish] > 1 context.step_out(@delayed[:finish] - 1) # Otherwise, resume the pry session at the stopped line. else resume_pry context end @delayed = Hash.new(0) end |
#debugging=(enabled) ⇒ Object
Adjust debugging. When set to false, the Processor will manage enabling and disabling the debugger itself. When set to true, byebug is always enabled.
58 59 60 61 62 63 64 65 66 |
# File 'lib/pry-byebug/processor.rb', line 58 def debugging=(enabled) if enabled @always_enabled = true Byebug.start unless Byebug.started? else @always_enabled = false # Byebug will get stopped if necessary in `stop` once the repl ends. end end |
#run(initial = true, &block) ⇒ Object
Wrap a Pry REPL to catch navigational commands and act on them.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pry-byebug/processor.rb', line 17 def run(initial = true, &block) return_value = nil command = catch(:breakout_nav) do # Throws from PryByebug::Commands return_value = yield {} # Nothing thrown == no navigational command end times = (command[:times] || 1).to_i # Command argument times = 1 if times <= 0 if [:step, :next, :finish].include? command[:action] @pry = command[:pry] # Pry instance to resume after stepping Byebug.start unless Byebug.started? if initial # Movement when on the initial binding.pry line will have a frame # inside Byebug. If we step normally, it'll stop inside this # Processor. So jump out and stop at the above frame, then step/next # from our callback. @delayed[command[:action]] = times Byebug.current_context.step_out(2) elsif :next == command[:action] Byebug.current_context.step_over(times, 0) elsif :step == command[:action] Byebug.current_context.step_into(times) elsif :finish == command[:action] Byebug.current_context.step_out(0) end else stop end return_value end |