Module: PryByebug::Breakpoints

Extended by:
Enumerable, Breakpoints
Included in:
Breakpoints
Defined in:
lib/pry-byebug/breakpoints.rb

Overview

Wrapper for Byebug.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)


11
12
13
14
15
16
17
18
19
20
# File 'lib/pry-byebug/breakpoints.rb', line 11

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)
  Byebug.add_breakpoint(path, line, expression)
end

#change(id, expression = nil) ⇒ Object

Change the conditional expression for a breakpoint.



23
24
25
26
27
28
29
# File 'lib/pry-byebug/breakpoints.rb', line 23

def change(id, expression = nil)
  validate_expression expression

  breakpoint = find_by_id(id)
  breakpoint.expr = expression
  breakpoint
end

#clearObject

Delete all breakpoints.



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

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

#delete(id) ⇒ Object

Delete an existing breakpoint with the given ID.



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

def delete(id)
  unless Byebug.started? && Byebug.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.



51
52
53
# File 'lib/pry-byebug/breakpoints.rb', line 51

def disable(id)
  change_status id, false
end

#disable_allObject

Disable all breakpoints.



56
57
58
59
60
# File 'lib/pry-byebug/breakpoints.rb', line 56

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

#each(&block) ⇒ Object



70
71
72
# File 'lib/pry-byebug/breakpoints.rb', line 70

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

#enable(id) ⇒ Object

Enable a disabled breakpoint with the given ID.



46
47
48
# File 'lib/pry-byebug/breakpoints.rb', line 46

def enable(id)
  change_status id, true
end

#find_by_id(id) ⇒ Object

Raises:

  • (ArgumentError)


74
75
76
77
78
# File 'lib/pry-byebug/breakpoints.rb', line 74

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

#sizeObject



66
67
68
# File 'lib/pry-byebug/breakpoints.rb', line 66

def size
  to_a.size
end

#to_aObject



62
63
64
# File 'lib/pry-byebug/breakpoints.rb', line 62

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