Class: Byebug::BreakCommand

Inherits:
Command
  • Object
show all
Includes:
Helpers::EvalHelper, Helpers::FileHelper, Helpers::ParseHelper
Defined in:
lib/byebug/commands/break.rb

Overview

Implements breakpoint functionality

Instance Attribute Summary

Attributes inherited from Command

#processor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ParseHelper

#get_int, #parse_steps, #syntax_valid?

Methods included from Helpers::FileHelper

#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?

Methods included from Helpers::EvalHelper

#error_eval, #multiple_thread_eval, #separate_thread_eval, #silent_eval, #warning_eval

Methods inherited from Command

#arguments, columnize, #context, #frame, help, #initialize, match, to_s

Methods included from Helpers::StringHelper

#camelize, #deindent, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/byebug/commands/break.rb', line 24

def self.description
  <<-DESCRIPTION
    b[reak] [<file>:]<line> [if <expr>]
    b[reak] [<module>::...]<class>(.|#)<method> [if <expr>]

    They can be specified by line or method and an expression can be added
    for conditionally enabled breakpoints.

    #{short_description}
  DESCRIPTION
end

.regexpObject



20
21
22
# File 'lib/byebug/commands/break.rb', line 20

def self.regexp
  /^\s* b(?:reak)? (?:\s+ (.+?))? (?:\s+ if \s+(.+))? \s*$/x
end

.short_descriptionObject



36
37
38
# File 'lib/byebug/commands/break.rb', line 36

def self.short_description
  "Sets breakpoints in the source code"
end

Instance Method Details

#executeObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/byebug/commands/break.rb', line 40

def execute
  return puts(help) unless @match[1]

  b = line_breakpoint(@match[1]) || method_breakpoint(@match[1])
  return errmsg(pr("break.errors.location")) unless b

  return puts(pr("break.created", id: b.id, file: b.source, line: b.pos)) if syntax_valid?(@match[2])

  errmsg(pr("break.errors.expression", expr: @match[2]))
  b.enabled = false
end