Module: PryDebuggerJRuby::Breakpoints

Extended by:
Enumerable, Breakpoints
Included in:
Breakpoints
Defined in:
lib/pry-debugger-jruby/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)


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

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

#change(id, expression = nil) ⇒ Object

Change the conditional expression for a breakpoint.



22
23
24
25
26
27
28
# File 'lib/pry-debugger-jruby/breakpoints.rb', line 22

def change(id, expression = nil)
  validate_expression expression

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

#clearObject

Delete all breakpoints.



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

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

#delete(id) ⇒ Object

Delete an existing breakpoint with the given ID.



31
32
33
34
35
36
# File 'lib/pry-debugger-jruby/breakpoints.rb', line 31

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.



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

def disable(id)
  change_status id, false
end

#disable_allObject

Disable all breakpoints.



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

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

#each(&block) ⇒ Object



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

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

#enable(id) ⇒ Object

Enable a disabled breakpoint with the given ID.



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

def enable(id)
  change_status id, true
end

#find_by_id(id) ⇒ Object

Raises:

  • (ArgumentError)


73
74
75
76
77
# File 'lib/pry-debugger-jruby/breakpoints.rb', line 73

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

#sizeObject



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

def size
  to_a.size
end

#to_aObject



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

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