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

Instance Method Details

#add(file, line, expression = nil) ⇒ Object

Add a new breakpoint.

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/pry-debugger/breakpoints.rb', line 12

def add(file, line, expression = nil)
  raise ArgumentError, 'Invalid file!' unless File.exist?(file)
  Pry.processor.debugging = true
  Debugger.add_breakpoint(File.expand_path(file), line, expression)
end

#change(id, expression = nil) ⇒ Object

Change the conditional expression for a breakpoint.



19
20
21
22
23
# File 'lib/pry-debugger/breakpoints.rb', line 19

def change(id, expression = nil)
  breakpoint = find_by_id(id)
  breakpoint.expr = expression
  breakpoint
end

#clearObject

Delete all breakpoints.



34
35
36
37
# File 'lib/pry-debugger/breakpoints.rb', line 34

def clear
  Debugger.breakpoints.clear if Debugger.started?
  Pry.processor.debugging = false
end

#delete(id) ⇒ Object

Delete an existing breakpoint with the given ID.



26
27
28
29
30
31
# File 'lib/pry-debugger/breakpoints.rb', line 26

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.



45
46
47
# File 'lib/pry-debugger/breakpoints.rb', line 45

def disable(id)
  change_status id, false
end

#disable_allObject

Disable all breakpoints.



50
51
52
53
54
# File 'lib/pry-debugger/breakpoints.rb', line 50

def disable_all
  each do |breakpoint|
    breakpoint.enabled = false
  end
end

#each(&block) ⇒ Object



64
65
66
# File 'lib/pry-debugger/breakpoints.rb', line 64

def each(&block)
  to_a.each(&block)
end

#enable(id) ⇒ Object

Enable a disabled breakpoint with the given ID.



40
41
42
# File 'lib/pry-debugger/breakpoints.rb', line 40

def enable(id)
  change_status id, true
end

#find_by_id(id) ⇒ Object

Raises:

  • (ArgumentError)


68
69
70
71
72
# File 'lib/pry-debugger/breakpoints.rb', line 68

def find_by_id(id)
  breakpoint = find { |b| b.id == id }
  raise ArgumentError, "No breakpoint ##{id}!" unless breakpoint
  breakpoint
end

#sizeObject



60
61
62
# File 'lib/pry-debugger/breakpoints.rb', line 60

def size
  to_a.size
end

#to_aObject



56
57
58
# File 'lib/pry-debugger/breakpoints.rb', line 56

def to_a
  Debugger.started? ? Debugger.breakpoints : []
end