module Crabfarm::Utils::Console

Constants

COLOR_ERROR
COLOR_HIGHLIGHT
COLOR_INFO
COLOR_QUESTION
COLOR_WARNING

Public Instance Methods

backtrace(_exc) click to toggle source
# File lib/crabfarm/utils/console.rb, line 54
def backtrace(_exc)
  _exc.backtrace.each { |i| info(i) }
end
error(_message) click to toggle source
# File lib/crabfarm/utils/console.rb, line 45
def error(_message)
  puts _message.color COLOR_ERROR
end
exception(_exc) click to toggle source
# File lib/crabfarm/utils/console.rb, line 49
def exception(_exc)
  error "#{_exc.class.to_s}: #{_exc.to_s}"
  backtrace _exc
end
info(_message) click to toggle source
# File lib/crabfarm/utils/console.rb, line 25
def info(_message)
  puts _message.color COLOR_INFO
end
json_result(_data) click to toggle source
# File lib/crabfarm/utils/console.rb, line 33
def json_result(_data)
  if _data.nil?
    result 'nil'
  else
    result JSON.pretty_generate(_data).gsub(/(^|\\n)/, '  ')
  end
end
operation(_message) click to toggle source
# File lib/crabfarm/utils/console.rb, line 21
def operation(_message)
  puts _message
end
question(_question) click to toggle source
# File lib/crabfarm/utils/console.rb, line 58
def question(_question)
  Ask.input(_question.color COLOR_QUESTION)
end
result(_message) click to toggle source
# File lib/crabfarm/utils/console.rb, line 29
def result(_message)
  puts _message.color COLOR_HIGHLIGHT
end
system(_message) click to toggle source
# File lib/crabfarm/utils/console.rb, line 17
def system(_message)
  puts _message
end
trap_errors(_context) { || ... } click to toggle source
# File lib/crabfarm/utils/console.rb, line 62
def trap_errors(_context)
  begin
    yield
  rescue SystemExit, Interrupt
    raise
  rescue Exception => e
    error = "Error #{_context}"
    warning error + ', check log for more information'
    Crabfarm.logger.error error
    Crabfarm.logger.error e
  end
end
warning(_message) click to toggle source
# File lib/crabfarm/utils/console.rb, line 41
def warning(_message)
  puts _message.color COLOR_WARNING
end