Module: PryDebugger::Breakpoints
- Extended by:
- Enumerable, Breakpoints
- Included in:
- Breakpoints
- Defined in:
- lib/pry-debugger/breakpoints.rb
Overview
Wrapper for Debugger.breakpoints that respects our Processor and has better failure behavior. Acts as an Enumerable.
Instance Method Summary collapse
-
#add(file, line, expression = nil) ⇒ Object
Add a new breakpoint.
-
#change(id, expression = nil) ⇒ Object
Change the conditional expression for a breakpoint.
-
#clear ⇒ Object
Delete all breakpoints.
-
#delete(id) ⇒ Object
Delete an existing breakpoint with the given ID.
-
#disable(id) ⇒ Object
Disable a breakpoint with the given ID.
-
#disable_all ⇒ Object
Disable all breakpoints.
- #each(&block) ⇒ Object
-
#enable(id) ⇒ Object
Enable a disabled breakpoint with the given ID.
- #find_by_id(id) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
Instance Method Details
#add(file, line, expression = nil) ⇒ Object
Add a new breakpoint.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pry-debugger/breakpoints.rb', line 12 def add(file, line, expression = nil) real_file = (file != Pry.eval_path) raise ArgumentError, 'Invalid file!' if real_file && !File.exist?(file) validate_expression expression Pry.processor.debugging = true path = (real_file ? File.(file) : file) Debugger.add_breakpoint(path, line, expression) end |
#change(id, expression = nil) ⇒ Object
Change the conditional expression for a breakpoint.
24 25 26 27 28 29 30 |
# File 'lib/pry-debugger/breakpoints.rb', line 24 def change(id, expression = nil) validate_expression expression breakpoint = find_by_id(id) breakpoint.expr = expression breakpoint end |
#clear ⇒ Object
Delete all breakpoints.
41 42 43 44 |
# File 'lib/pry-debugger/breakpoints.rb', line 41 def clear Debugger.breakpoints.clear if Debugger.started? Pry.processor.debugging = false end |
#delete(id) ⇒ Object
Delete an existing breakpoint with the given ID.
33 34 35 36 37 38 |
# File 'lib/pry-debugger/breakpoints.rb', line 33 def delete(id) unless Debugger.started? && Debugger.remove_breakpoint(id) raise ArgumentError, "No breakpoint ##{id}" end Pry.processor.debugging = false if to_a.empty? end |
#disable(id) ⇒ Object
Disable a breakpoint with the given ID.
52 53 54 |
# File 'lib/pry-debugger/breakpoints.rb', line 52 def disable(id) change_status id, false end |
#disable_all ⇒ Object
Disable all breakpoints.
57 58 59 60 61 |
# File 'lib/pry-debugger/breakpoints.rb', line 57 def disable_all each do |breakpoint| breakpoint.enabled = false end end |
#each(&block) ⇒ Object
71 72 73 |
# File 'lib/pry-debugger/breakpoints.rb', line 71 def each(&block) to_a.each(&block) end |
#enable(id) ⇒ Object
Enable a disabled breakpoint with the given ID.
47 48 49 |
# File 'lib/pry-debugger/breakpoints.rb', line 47 def enable(id) change_status id, true end |
#find_by_id(id) ⇒ Object
75 76 77 78 79 |
# File 'lib/pry-debugger/breakpoints.rb', line 75 def find_by_id(id) breakpoint = find { |b| b.id == id } raise ArgumentError, "No breakpoint ##{id}!" unless breakpoint breakpoint end |
#size ⇒ Object
67 68 69 |
# File 'lib/pry-debugger/breakpoints.rb', line 67 def size to_a.size end |
#to_a ⇒ Object
63 64 65 |
# File 'lib/pry-debugger/breakpoints.rb', line 63 def to_a Debugger.started? ? Debugger.breakpoints : [] end |