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.

Defined Under Namespace

Classes: FileBreakpoint, MethodBreakpoint

Instance Method Summary collapse

Instance Method Details

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

Add file breakpoint.

Raises:

  • (ArgumentError)


51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pry-byebug/breakpoints.rb', line 51

def add_file(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)
  bp = FileBreakpoint.new Byebug.add_breakpoint(path, line, expression)
  breakpoints << bp
  bp
end

#add_method(method, expression = nil) ⇒ Object

Add method breakpoint.



40
41
42
43
44
45
46
47
48
# File 'lib/pry-byebug/breakpoints.rb', line 40

def add_method(method, expression = nil)
  validate_expression expression
  Pry.processor.debugging = true
  owner, name = method.split(/[\.#]/)
  byebug_bp = Byebug.add_breakpoint(owner, name.to_sym, expression)
  bp = MethodBreakpoint.new byebug_bp, method
  breakpoints << bp
  bp
end

#breakpointsObject



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

def breakpoints
  @breakpoints ||= []
end

#change(id, expression = nil) ⇒ Object

Change the conditional expression for a breakpoint.



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

def change(id, expression = nil)
  validate_expression expression

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

#clearObject

Delete all breakpoints.



83
84
85
86
87
# File 'lib/pry-byebug/breakpoints.rb', line 83

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

#delete(id) ⇒ Object

Delete an existing breakpoint with the given ID.

Raises:

  • (ArgumentError)


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

def delete(id)
  deleted = Byebug.started? && 
    Byebug.remove_breakpoint(id) &&
    breakpoints.delete(find_by_id(id))
  raise ArgumentError, "No breakpoint ##{id}" if not deleted
  Pry.processor.debugging = false if to_a.empty?
end

#disable(id) ⇒ Object

Disable a breakpoint with the given ID.



95
96
97
# File 'lib/pry-byebug/breakpoints.rb', line 95

def disable(id)
  change_status id, false
end

#disable_allObject

Disable all breakpoints.



100
101
102
103
104
# File 'lib/pry-byebug/breakpoints.rb', line 100

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

#each(&block) ⇒ Object



114
115
116
# File 'lib/pry-byebug/breakpoints.rb', line 114

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

#enable(id) ⇒ Object

Enable a disabled breakpoint with the given ID.



90
91
92
# File 'lib/pry-byebug/breakpoints.rb', line 90

def enable(id)
  change_status id, true
end

#find_by_id(id) ⇒ Object

Raises:

  • (ArgumentError)


118
119
120
121
122
# File 'lib/pry-byebug/breakpoints.rb', line 118

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

#sizeObject



110
111
112
# File 'lib/pry-byebug/breakpoints.rb', line 110

def size
  to_a.size
end

#to_aObject



106
107
108
# File 'lib/pry-byebug/breakpoints.rb', line 106

def to_a
  breakpoints
end