Class: Babushka::Logging
- Inherits:
-
Object
show all
- Extended by:
- LogHelpers
- Defined in:
- lib/babushka/helpers/log_helpers.rb
Constant Summary
- TickChar =
'✓'
- CrossChar =
'✗'
Class Method Summary
(collapse)
Methods included from LogHelpers
debug, log, log_block, log_error, log_ok, log_verbose, log_warn
Class Method Details
+ (Object) closing_log_message(message, result = true, opts = {})
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/babushka/helpers/log_helpers.rb', line 115
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 ? TickChar : CrossChar}".colorize(result ? 'green' : 'red')
elsif opts[:closing_status] == :dry_run
'}'.colorize('grey') + ' ' + "#{result ? TickChar : '~'} #{message}".colorize(result ? 'green' : 'blue')
elsif opts[:closing_status]
'}'.colorize('grey') + ' ' + "#{result ? TickChar : CrossChar} #{message}".colorize(result ? 'green' : 'red')
else
"}".colorize('grey')
end
end
|
+ (Object) log_table(headings, rows)
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/babushka/helpers/log_helpers.rb', line 129
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
|