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)
  if !File.exist?(file) && file != Pry.eval_path
    raise ArgumentError, 'Invalid file!' unless File.exist?(file)
  end
  validate_expression expression

  Pry.processor.debugging = true

  path = file == Pry.eval_path ? file : File.expand_path(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 25
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 42
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 34
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 53
def disable(id)
  change_status id, false
end
disable_all() click to toggle source

Disable all breakpoints.

# File lib/pry-debugger/breakpoints.rb, line 58
def disable_all
  each do |breakpoint|
    breakpoint.enabled = false
  end
end
each(&block) click to toggle source
# File lib/pry-debugger/breakpoints.rb, line 72
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 48
def enable(id)
  change_status id, true
end
find_by_id(id) click to toggle source
# File lib/pry-debugger/breakpoints.rb, line 76
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 68
def size
  to_a.size
end
to_a() click to toggle source
# File lib/pry-debugger/breakpoints.rb, line 64
def to_a
  Debugger.started? ? Debugger.breakpoints : []
end