class PryByebug::BreakCommand
Add, show and remove breakpoints
def add_breakpoint(place, condition)
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
def new_breakpoint
def new_breakpoint place = args.shift condition = args.join(" ") if args.shift == "if" bp = add_breakpoint(place, condition) print_full_breakpoint(bp) end
def option_to_method(option)
def option_to_method(option) "process_#{option.to_s.tr('-', '_')}" end
def options(opt)
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
def print_all
def print_all print_breakpoints_header breakpoints.each { |b| print_short_breakpoint(b) } end
def process
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
def process_condition
def process_condition expr = args.empty? ? nil : args.join(" ") breakpoints.change(opts[:condition], expr) end
def process_show
def process_show print_full_breakpoint(breakpoints.find_by_id(opts[:show])) end