class PryByebug::BreakCommand

Add, show and remove breakpoints

Public Instance Methods

options(opt) click to toggle source
# File lib/pry-byebug/commands/breakpoint.rb, line 46
def options(opt)
  defaults = { argument: true, as: Integer }

  opt.on :c, :condition, "Change condition of a breakpoint.", defaults
  opt.on :s, :show, "Show breakpoint details and source.", defaults
  opt.on :D, :delete, "Delete a breakpoint.", defaults
  opt.on :d, :disable, "Disable a breakpoint.", defaults
  opt.on :e, :enable, "Enable a disabled breakpoint.", defaults
  opt.on :'disable-all', "Disable all breakpoints."
  opt.on :'delete-all', "Delete all breakpoints."
end
process() click to toggle source
# File lib/pry-byebug/commands/breakpoint.rb, line 58
def process
  return if check_multiline_context

  PryByebug.check_file_context(target)

  option, = opts.to_hash.find { |key, _value| opts.present?(key) }
  return send(option_to_method(option)) if option

  return new_breakpoint unless args.empty?

  print_all
end

Private Instance Methods

add_breakpoint(place, condition) click to toggle source
# File lib/pry-byebug/commands/breakpoint.rb, line 107
def add_breakpoint(place, condition)
  case place
  when /^(\d+)$/
    errmsg = "Line number declaration valid only in a file context."
    PryByebug.check_file_context(target, errmsg)

    lineno = Regexp.last_match[1].to_i
    breakpoints.add_file(current_file, lineno, condition)
  when /^(.+):(\d+)$/
    file = Regexp.last_match[1]
    lineno = Regexp.last_match[2].to_i
    breakpoints.add_file(file, lineno, condition)
  when /^(.*)[.#].+$/ # Method or class name
    if Regexp.last_match[1].strip.empty?
      errmsg = "Method name declaration valid only in a file context."
      PryByebug.check_file_context(target, errmsg)
      place = target.eval("self.class.to_s") + place
    end
    breakpoints.add_method(place, condition)
  else
    raise(ArgumentError, "Cannot identify arguments as breakpoint")
  end
end
new_breakpoint() click to toggle source
# File lib/pry-byebug/commands/breakpoint.rb, line 89
def new_breakpoint
  place = args.shift
  condition = args.join(" ") if args.shift == "if"

  bp = add_breakpoint(place, condition)

  print_full_breakpoint(bp)
end
option_to_method(option) click to toggle source
# File lib/pry-byebug/commands/breakpoint.rb, line 98
def option_to_method(option)
  "process_#{option.to_s.tr('-', '_')}"
end
print_all() click to toggle source
process_condition() click to toggle source
# File lib/pry-byebug/commands/breakpoint.rb, line 84
def process_condition
  expr = args.empty? ? nil : args.join(" ")
  breakpoints.change(opts[:condition], expr)
end
process_show() click to toggle source
# File lib/pry-byebug/commands/breakpoint.rb, line 80
def process_show
  print_full_breakpoint(breakpoints.find_by_id(opts[:show]))
end