Module: Bovem::ConsoleMethods::Logging
- Extended by:
- ActiveSupport::Concern
- Included in:
- Bovem::Console
- Defined in:
- lib/bovem/console.rb
Overview
Methods for logging activities to the user.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary (collapse)
-
- (Object) begin(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
Writes a message prepending a green banner.
-
- (Object) debug(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
Writes a message prepending a magenta banner.
-
- (Object) error(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
Writes a message prepending a red banner.
-
- (Object) fatal(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, return_code = -1,, print = true)
Writes a message prepending a red banner and then quits the application.
-
- (String) get_banner(label, base_color, full_colored = false, bracket_color = "blue", brackets = ["[", "]"])
Gets a banner for the messages.
-
- (Object) info(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true, *banner)
Writes a message prepending a cyan banner.
-
- (String) progress(current, total, type = :list, precision = 0)
Formats a progress for pretty printing.
-
- (Array) status(status, plain = false, go_up = true, right = true, print = true)
Writes a status to the output.
-
- (Object) warn(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
Writes a message prepending a yellow banner.
-
- (String) write(message, suffix = "\n", indent = true, wrap = false, plain = false, print = true)
Writes a message.
-
- (String) write_banner_aligned(message, suffix = "\n", indent = true, wrap = false, plain = false, print = true)
Writes a message, aligning to a call with an empty banner.
Instance Method Details
- (Object) begin(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
Writes a message prepending a green banner.
366 367 368 369 370 |
# File 'lib/bovem/console.rb', line 366 def begin(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true) = ("*", "bright green", full_colored) = indent(, ? 0 : indent) write( + " " + , suffix, ? indent : 0, wrap, plain, print) end |
- (Object) debug(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
Writes a message prepending a magenta banner.
423 424 425 |
# File 'lib/bovem/console.rb', line 423 def debug(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true) info(, suffix, indent, wrap, plain, , full_colored, print, ["D", "bright magenta"]) end |
- (Object) error(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
Writes a message prepending a red banner.
456 457 458 |
# File 'lib/bovem/console.rb', line 456 def error(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true) info(, suffix, indent, wrap, plain, , full_colored, print, "E", "bright red") end |
- (Object) fatal(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, return_code = -1,, print = true)
Writes a message prepending a red banner and then quits the application.
385 386 387 388 |
# File 'lib/bovem/console.rb', line 385 def fatal(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, return_code = -1, print = true) error(, suffix, indent, wrap, plain, , full_colored, print) Kernel.exit(return_code.to_integer(-1)) end |
- (String) get_banner(label, base_color, full_colored = false, bracket_color = "blue", brackets = ["[", "]"])
Gets a banner for the messages.
328 329 330 331 332 333 |
# File 'lib/bovem/console.rb', line 328 def (label, base_color, full_colored = false, bracket_color = "blue", brackets = ["[", "]"]) label = label.rjust(Bovem::Console., " ") brackets = brackets.ensure_array bracket_color = base_color if full_colored "{mark=%s}%s{mark=%s}%s{/mark}%s{/mark}" % [bracket_color.parameterize, brackets[0], base_color.parameterize, label, brackets[1]] end |
- (Object) info(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true, *banner)
Writes a message prepending a cyan banner.
403 404 405 406 407 408 409 |
# File 'lib/bovem/console.rb', line 403 def info(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true, *) = .ensure_array(nil, true, true, true) = ["I", "bright cyan"] if .blank? = ([0], [1], full_colored) = indent(, ? 0 : indent) write( + " " + , suffix, ? indent : 0, wrap, plain, print) end |
- (String) progress(current, total, type = :list, precision = 0)
Formats a progress for pretty printing.
342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/bovem/console.rb', line 342 def progress(current, total, type = :list, precision = 0) if type == :list then @progress_list_widths ||= {} @progress_list_widths[total] ||= total.to_s.length "%0#{@progress_list_widths[total]}d/%d" % [current, total] else precision = [0, precision].max result = total == 0 ? 100 : (100 * (current.to_f / total)) ("%0.#{precision}f %%" % result.round(precision)).rjust(5 + (precision > 0 ? precision + 1 : 0)) end end |
- (Array) status(status, plain = false, go_up = true, right = true, print = true)
Writes a status to the output. Valid values are :ok
, :pass
, :fail
, :warn
.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/bovem/console.rb', line 295 def status(status, plain = false, go_up = true, right = true, print = true) statuses = { ok: {label: " OK ", color: "bright green"}, pass: {label: "PASS", color: "bright cyan"}, warn: {label: "WARN", color: "bright yellow"}, fail: {label: "FAIL", color: "bright red"} } statuses.default = statuses[:ok] rv = statuses[status] if print then = (rv[:label], rv[:color]) if right then Kernel.puts(format_right( + " ", true, go_up, plain)) else Kernel.puts(format( + " ", "\n", true, true, plain)) end end rv end |
- (Object) warn(message, suffix = "\n", indent = true, wrap = false, plain = false, indented_banner = false, full_colored = false, print = true)
Writes a message prepending a yellow banner.
439 440 441 442 |
# File 'lib/bovem/console.rb', line 439 def warn(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true) = ["W", "bright yellow"] info(, suffix, indent, wrap, plain, , full_colored, print, ) end |
- (String) write(message, suffix = "\n", indent = true, wrap = false, plain = false, print = true)
Writes a message.
266 267 268 269 270 |
# File 'lib/bovem/console.rb', line 266 def write(, suffix = "\n", indent = true, wrap = false, plain = false, print = true) rv = format(, suffix, indent, wrap, plain) Kernel.puts(rv) if print rv end |
- (String) write_banner_aligned(message, suffix = "\n", indent = true, wrap = false, plain = false, print = true)
Writes a message, aligning to a call with an empty banner.
283 284 285 |
# File 'lib/bovem/console.rb', line 283 def (, suffix = "\n", indent = true, wrap = false, plain = false, print = true) write((" " * (Bovem::Console. + 3)) + .ensure_string, suffix, indent, wrap, plain, print) end |