module PryDebugger::Breakpoints
Wrapper for Debugger.breakpoints that respects our Processor
and has better failure behavior. Acts as an Enumerable.
Public Instance Methods
add(file, line, expression = nil)
click to toggle source
Add a new breakpoint.
# 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.expand_path(file) : file) Debugger.add_breakpoint(path, line, expression) end
change(id, expression = nil)
click to toggle source
Change the conditional expression for a breakpoint.
# 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()
click to toggle source
Delete all breakpoints.
# File lib/pry-debugger/breakpoints.rb, line 41 def clear Debugger.breakpoints.clear if Debugger.started? Pry.processor.debugging = false end
delete(id)
click to toggle source
Delete an existing breakpoint with the given ID.
# 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)
click to toggle source
Disable a breakpoint with the given ID.
# File lib/pry-debugger/breakpoints.rb, line 52 def disable(id) change_status id, false end
disable_all()
click to toggle source
Disable all breakpoints.
# File lib/pry-debugger/breakpoints.rb, line 57 def disable_all each do |breakpoint| breakpoint.enabled = false end end
each(&block)
click to toggle source
# File lib/pry-debugger/breakpoints.rb, line 71 def each(&block) to_a.each(&block) end
enable(id)
click to toggle source
Enable a disabled breakpoint with the given ID.
# File lib/pry-debugger/breakpoints.rb, line 47 def enable(id) change_status id, true end
find_by_id(id)
click to toggle source
# 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()
click to toggle source
# File lib/pry-debugger/breakpoints.rb, line 67 def size to_a.size end
to_a()
click to toggle source
# File lib/pry-debugger/breakpoints.rb, line 63 def to_a Debugger.started? ? Debugger.breakpoints : [] end
Private Instance Methods
change_status(id, enabled = true)
click to toggle source
# File lib/pry-debugger/breakpoints.rb, line 84 def change_status(id, enabled = true) breakpoint = find_by_id(id) breakpoint.enabled = enabled breakpoint end
validate_expression(expression)
click to toggle source
# File lib/pry-debugger/breakpoints.rb, line 90 def validate_expression(expression) if expression && # `nil` implies no expression given, so pass (expression.empty? || !Pry::Code.complete_expression?(expression)) raise "Invalid breakpoint conditional: #{expression}" end end