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.
-
- (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.
347 348 349 350 351 |
# File 'lib/bovem/console.rb', line 347 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.
404 405 406 |
# File 'lib/bovem/console.rb', line 404 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.
437 438 439 |
# File 'lib/bovem/console.rb', line 437 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.
366 367 368 369 |
# File 'lib/bovem/console.rb', line 366 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.
384 385 386 387 388 389 390 |
# File 'lib/bovem/console.rb', line 384 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 |
- (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.
420 421 422 423 |
# File 'lib/bovem/console.rb', line 420 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 |