module Comandante::Helper
Overview
Some helper functions
Defined in:
comandante/helper.crConstant Summary
-
EMPTY_STRING_ARRAY =
Array(String).new
Class Method Summary
-
.assert(cond, msg) : Nil
Asserts a condition, depending on
Cleaner
will either exit with message or raise an error -
.assert_directory(dir) : Nil
Asserts that a directory exists
-
.assert_file(file) : Nil
Asserts that a file exists
-
.debug_inspect(val, context = "")
Prints a colorized inspect of val if
Cleaner
is in debug mode -
.file_md5sum(path) : String
Returns md5 digest for file
-
.file_sha1sum(path) : String
Returns sha1 digest for file
-
.file_sha256sum(path) : String
Returns sha256 digest for file
-
.file_sha512sum(path) : String
Returns sha512 digest for file
-
.mkdir(dir : String, verbose = false)
mkdir with verbose option
-
.parse_yaml(str, context = "") : YAML::Any
Parses yaml string and fails with message, context is used in error messages
-
.put_debug(msg, pref = "Debug: ")
Prints a debug message if
Cleaner
is in debug mode -
.put_error(msg, pref = "Error: ")
Prints an error message to STDERR
-
.put_verbose(msg)
Prints a message to STDERR if in verbose mode
-
.put_warning(msg, pref = "Warning: ")
Prints a warning message to STDERR
-
.read_gzip(path, &) : Nil
Reads gziped file line by line
-
.read_gzip(path) : String
Reads gziped file into a string
-
.read_yaml(file : String) : YAML::Any
Parses yaml from file and fails with message
-
.run(cmd, args = EMPTY_STRING_ARRAY, msg = "cmd failed") : Nil
Runs a command using system and raises if command fails
-
.string_md5sum(path) : String
Returns md5 digest for string
-
.string_sha1sum(path) : String
Returns sha1 digest for string
-
.string_sha256sum(path) : String
Returns sha256 digest for string
-
.string_sha512sum(path) : String
Returns sha512 digest for string
-
.string_to_file(str, file) : Nil
Writes String to a file
-
.timer(&)
Timer for a block of commands, prints time at the end Examples
-
.write_binary_file(file : String, data : Bytes)
Writes Bytes to a file
-
.write_gzip(str, path) : Nil
Writes gziped file from a string
Class Method Detail
Asserts a condition, depending on Cleaner
will either exit with
message or raise an error
Example:
assert(value > 0, "Expecting a value > 0")
Prints a colorized inspect of val if Cleaner
is in debug mode
Example:
debug_inspect(@opts, context: "@opts")
debug_inspect({test: x == y})
debug_inspect(["one", "two"])
Parses yaml string and fails with message, context is used in error messages
Reads gziped file line by line
read_gzip(path) { |line| puts line }
Runs a command using system and raises if command fails
Timer for a block of commands, prints time at the end Examples
timer { do_something }