Class: Babushka::Logging

Inherits:
Object show all
Extended by:
LogHelpers
Defined in:
lib/babushka/helpers/log_helpers.rb

Constant Summary

TICK_CHAR =
''
CROSS_CHAR =
''

Class Method Summary collapse

Methods included from LogHelpers

debug, deprecated!, log, log_block, log_error, log_ok, log_stderr, log_warn, removed!

Class Method Details

.closing_log_message(message, result = true, opts = {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/babushka/helpers/log_helpers.rb', line 140

def self.closing_log_message message, result = true, opts = {}
  message = opts[:closing_status] if opts[:closing_status].is_a?(String)

  if opts[:closing_status] == :status_only
    '}'.colorize('grey') + ' ' + "#{result ? TICK_CHAR : CROSS_CHAR}".colorize(result ? 'green' : 'red')
  elsif opts[:closing_status] == :dry_run
    '}'.colorize('grey') + ' ' + "#{result ? TICK_CHAR : '~'} #{message}".colorize(result ? 'green' : 'blue')
  elsif opts[:closing_status]
    '}'.colorize('grey') + ' ' + "#{result ? TICK_CHAR : CROSS_CHAR} #{message}".colorize(result ? 'green' : 'red')
  else
    "}".colorize('grey')
  end
end

.log_exception(exception) ⇒ Object



154
155
156
157
# File 'lib/babushka/helpers/log_helpers.rb', line 154

def self.log_exception exception
  log_error "#{exception.backtrace.first}: #{exception.message}"
  debug exception.backtrace * "\n"
end

.log_table(headings, rows) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/babushka/helpers/log_helpers.rb', line 159

def self.log_table headings, rows
  all_rows = rows.map {|row|
    row.map(&:to_s)
  }.unshift(
    headings
  ).transpose.map {|col|
    max_length = col.map(&:length).max
    col.map {|cell| cell.ljust(max_length) }
  }.transpose

  [
    all_rows.first.join(' | '),
    all_rows.first.map {|i| '-' * i.length }.join('-+-')
  ].concat(
    all_rows[1..-1].map {|row| row.join(' | ') }
  ).each {|row|
    log row
  }
end