Module: Pry::Byebug::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

Adds a file breakpoint.

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
68
69
70
# File 'lib/pry/byebug/breakpoints.rb', line 61

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

  path = (real_file ? File.expand_path(file) : file)
  bp = FileBreakpoint.new ::Byebug::Breakpoint.add(path, line, expression)
  breakpoints << bp
  bp
end

#add_method(method, expression = nil) ⇒ Object

Adds a method breakpoint.



49
50
51
52
53
54
55
56
# File 'lib/pry/byebug/breakpoints.rb', line 49

def add_method(method, expression = nil)
  validate_expression expression
  owner, name = method.split(/[\.#]/)
  byebug_bp = ::Byebug::Breakpoint.add(owner, name.to_sym, expression)
  bp = MethodBreakpoint.new byebug_bp, method
  breakpoints << bp
  bp
end

#breakpointsObject



42
43
44
# File 'lib/pry/byebug/breakpoints.rb', line 42

def breakpoints
  @breakpoints ||= []
end

#change(id, expression = nil) ⇒ Object

Changes the conditional expression for a breakpoint.



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

def change(id, expression = nil)
  validate_expression expression

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

#delete(id) ⇒ Object

Deletes an existing breakpoint with the given ID.

Raises:

  • (ArgumentError)


86
87
88
89
90
91
92
93
# File 'lib/pry/byebug/breakpoints.rb', line 86

def delete(id)
  deleted =
    ::Byebug.started? &&
    ::Byebug::Breakpoint.remove(id) &&
    breakpoints.delete(find_by_id(id))

  raise(ArgumentError, "No breakpoint ##{id}") unless deleted
end

#delete_allObject

Deletes all breakpoints.



98
99
100
101
# File 'lib/pry/byebug/breakpoints.rb', line 98

def delete_all
  @breakpoints = []
  ::Byebug.breakpoints.clear if ::Byebug.started?
end

#disable(id) ⇒ Object

Disables a breakpoint with the given ID.



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

def disable(id)
  change_status id, false
end

#disable_allObject

Disables all breakpoints.



120
121
122
123
124
# File 'lib/pry/byebug/breakpoints.rb', line 120

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

#each(&block) ⇒ Object



134
135
136
# File 'lib/pry/byebug/breakpoints.rb', line 134

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

#enable(id) ⇒ Object

Enables a disabled breakpoint with the given ID.



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

def enable(id)
  change_status id, true
end

#find_by_id(id) ⇒ Object

Raises:

  • (ArgumentError)


142
143
144
145
146
# File 'lib/pry/byebug/breakpoints.rb', line 142

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

#lastObject



138
139
140
# File 'lib/pry/byebug/breakpoints.rb', line 138

def last
  to_a.last
end

#sizeObject



130
131
132
# File 'lib/pry/byebug/breakpoints.rb', line 130

def size
  to_a.size
end

#to_aObject



126
127
128
# File 'lib/pry/byebug/breakpoints.rb', line 126

def to_a
  breakpoints
end