Module: Crabfarm::Utils::Console
Constant Summary collapse
- COLOR_INFO =
'888888'
- COLOR_QUESTION =
'888888'
- COLOR_WARNING =
:yellow
- COLOR_ERROR =
:red
- COLOR_HIGHLIGHT =
'00FF00'
Instance Method Summary collapse
- #backtrace(_exc) ⇒ Object
- #error(_message) ⇒ Object
- #exception(_exc) ⇒ Object
- #info(_message) ⇒ Object
- #json_result(_data) ⇒ Object
- #operation(_message) ⇒ Object
- #question(_question) ⇒ Object
- #result(_message) ⇒ Object
- #system(_message) ⇒ Object
- #trap_errors(_context) ⇒ Object
- #warning(_message) ⇒ Object
Instance Method Details
#backtrace(_exc) ⇒ Object
54 55 56 |
# File 'lib/crabfarm/utils/console.rb', line 54 def backtrace(_exc) _exc.backtrace.each { |i| info(i) } end |
#error(_message) ⇒ Object
45 46 47 |
# File 'lib/crabfarm/utils/console.rb', line 45 def error() puts .color COLOR_ERROR end |
#exception(_exc) ⇒ Object
49 50 51 52 |
# File 'lib/crabfarm/utils/console.rb', line 49 def exception(_exc) error "#{_exc.class.to_s}: #{_exc.to_s}" backtrace _exc end |
#info(_message) ⇒ Object
25 26 27 |
# File 'lib/crabfarm/utils/console.rb', line 25 def info() puts .color COLOR_INFO end |
#json_result(_data) ⇒ Object
33 34 35 36 37 38 39 |
# 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) ⇒ Object
21 22 23 |
# File 'lib/crabfarm/utils/console.rb', line 21 def operation() puts end |
#question(_question) ⇒ Object
58 59 60 |
# File 'lib/crabfarm/utils/console.rb', line 58 def question(_question) Ask.input(_question.color COLOR_QUESTION) end |
#result(_message) ⇒ Object
29 30 31 |
# File 'lib/crabfarm/utils/console.rb', line 29 def result() puts .color COLOR_HIGHLIGHT end |
#system(_message) ⇒ Object
17 18 19 |
# File 'lib/crabfarm/utils/console.rb', line 17 def system() puts end |
#trap_errors(_context) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/crabfarm/utils/console.rb', line 41 def warning() puts .color COLOR_WARNING end |