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.
353 354 355 356 357 |
# File 'lib/bovem/console.rb', line 353 def begin(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true) = self.("*", "bright green") = self.indent(, ? 0 : indent) self.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.
410 411 412 |
# File 'lib/bovem/console.rb', line 410 def debug(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true) self.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.
443 444 445 |
# File 'lib/bovem/console.rb', line 443 def error(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true) self.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.
372 373 374 375 |
# File 'lib/bovem/console.rb', line 372 def fatal(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, return_code = -1, print = true) self.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.
334 335 336 337 338 339 |
# File 'lib/bovem/console.rb', line 334 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.
390 391 392 393 394 395 396 |
# File 'lib/bovem/console.rb', line 390 def info(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true, *) = .ensure_array.flatten = ["I", "bright cyan"] if .blank? = self.([0], [1], full_colored) = self.indent(, ? 0 : indent) self.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
.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/bovem/console.rb', line 301 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 = self.(rv[:label], rv[:color]) if right then Kernel.puts self.format_right( + " ", true, go_up, plain) else Kernel.puts self.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.
426 427 428 429 |
# File 'lib/bovem/console.rb', line 426 def warn(, suffix = "\n", indent = true, wrap = false, plain = false, = false, full_colored = false, print = true) = ["W", "bright yellow"] self.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.
272 273 274 275 276 |
# File 'lib/bovem/console.rb', line 272 def write(, suffix = "\n", indent = true, wrap = false, plain = false, print = true) rv = self.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.
289 290 291 |
# File 'lib/bovem/console.rb', line 289 def (, suffix = "\n", indent = true, wrap = false, plain = false, print = true) self.write((" " * (::Bovem::Console. + 3)) + .ensure_string, suffix, indent, wrap, plain, print) end |