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.



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)
  fail(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.



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

def delete(id)
  deleted = ::Byebug.started? &&
    ::Byebug::Breakpoint.remove(id) && breakpoints.delete(find_by_id(id))
  fail(ArgumentError, "No breakpoint ##{id}") unless deleted
end

#delete_allObject

Deletes all breakpoints.



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

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

#disable(id) ⇒ Object

Disables a breakpoint with the given ID.



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

def disable(id)
  change_status id, false
end

#disable_allObject

Disables all breakpoints.



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

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

#each(&block) ⇒ Object



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

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

#enable(id) ⇒ Object

Enables a disabled breakpoint with the given ID.



103
104
105
# File 'lib/pry/byebug/breakpoints.rb', line 103

def enable(id)
  change_status id, true
end

#find_by_id(id) ⇒ Object



135
136
137
138
139
# File 'lib/pry/byebug/breakpoints.rb', line 135

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

#sizeObject



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

def size
  to_a.size
end

#to_aObject



123
124
125
# File 'lib/pry/byebug/breakpoints.rb', line 123

def to_a
  breakpoints
end