Module: AIPP::Debugger

Included in:
Downloader, Executable, Parser, Runner
Defined in:
lib/aipp/debugger.rb

Instance Method Summary collapse

Instance Method Details

#info(message, color: nil) ⇒ Object

Issue an informational message.

Parameters:

  • message (String)

    informational message

  • color (Symbol) (defaults to: nil)

    message color



60
61
62
63
64
# File 'lib/aipp/debugger.rb', line 60

def info(message, color: nil)
  unless AIPP.options.quiet
    puts color ? message.upcase_first.send(color) : message.upcase_first
  end
end

#original_warnObject



42
# File 'lib/aipp/debugger.rb', line 42

alias_method :original_warn, :warn

#verbose_info(message, color: :blue) ⇒ Object

Issue a verbose informational message.

Parameters:

  • message (String)

    verbose informational message

  • color (Symbol) (defaults to: :blue)

    message color



70
71
72
# File 'lib/aipp/debugger.rb', line 70

def verbose_info(message, color: :blue)
  info(message, color: color) if AIPP.options.verbose
end

#warn(message, severe: true) ⇒ Object

Issue a warning and maybe open a debug session.

Parameters:

  • message (String)

    warning message

  • severe (Boolean) (defaults to: true)

    whether this problem must be fixed or not



48
49
50
51
52
53
54
# File 'lib/aipp/debugger.rb', line 48

def warn(message, severe: true)
  if severe || AIPP.options.verbose
    AIPP.cache.debug_counter += 1
    original_warn "WARNING #{AIPP.cache.debug_counter}: #{message.upcase_first} #{'(unsevere)' unless severe}".red
    debugger if AIPP.options.debug_on_warning == true || AIPP.options.debug_on_warning == AIPP.cache.debug_counter
  end
end

#with_debugger(debug_on_warning: , debug_on_error: , verbose: ) { ... } ⇒ Object

Note:

The debugger session persists beyond the scope of the given block because there’s no DEBUGGER__.stop as of now.

Start a debugger session and watch for warnings etc

Examples:

include AIPP::Debugger
with_debugger(verbose: true) do
  (...)
  warn("all hell broke loose", severe: true)
end

Parameters:

  • debug_on_warning (Boolean, Integer) (defaults to: )

    start a debugger session which opens a console on the warning with the given integer ID or on all warnings if true is given

  • debug_on_error (Boolean) (defaults to: )

    start a debugger session which opens a console when an error is raised (postmortem)

  • verbose (Boolean) (defaults to: )

    print verbose info, print unsevere warnings and re-raise rescued errors

Yields:

  • Block the debugger is watching



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aipp/debugger.rb', line 25

def with_debugger(&)
  AIPP.cache.debug_counter = 0
  case
  when id = AIPP.options.debug_on_warning
    puts instructions_for(@id == true ? 'warning' : "warning #{id}")
    DEBUGGER__::start(no_sigint_hook: true, nonstop: true)
    call_with_rescue(&)
  when AIPP.options.debug_on_error
    puts instructions_for('error')
    DEBUGGER__::start(no_sigint_hook: true, nonstop: true, postmortem: true)
    call_without_rescue(&)
  else
    DEBUGGER__::start(no_sigint_hook: true, nonstop: true)
    call_with_rescue(&)
  end
end