module Comandante::Helper::YamlTo(T)

A from_yaml wrapper that exits/raises on failure

Example

x = YamlTo(Array(Int32)).load("[1,2,3]", ":config")

Class methods

.load(s, context = "") : T

View source

module Comandante::Helper

Some helper functions

Constants

EMPTY_STRING_ARRAY = Array(String).new

Class methods

.assert(cond, msg) : Nil

Asserts a condition, depending on Cleaner will either exit with message or raise an error

Example:

assert(value > 0, "Expecting a value > 0")
View source

.assert_directory(dir) : Nil

Asserts that a directory exists

View source

.assert_file(file) : Nil

Asserts that a file exists

View source

.debug_inspect(val, context = "")

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"])
View source

.file_md5sum(path) : String

Returns md5 digest for file

View source

.file_sha1sum(path) : String

Returns sha1 digest for file

View source

.file_sha256sum(path) : String

Returns sha256 digest for file

View source

.file_sha512sum(path) : String

Returns sha512 digest for file

View source

.mkdir(dir : String, verbose = false)

mkdir with verbose option

View source

.parse_yaml(str, context = "") : YAML::Any

Parses yaml string and fails with message, context is used in error messages

View source

.put_debug(msg, pref = "Debug: ")

Prints a debug message if Cleaner is in debug mode

View source

.put_error(msg, pref = "Error: ")

Prints an error message to STDERR

View source

.put_verbose(msg)

Prints a message to STDERR if in verbose mode

View source

.put_warning(msg, pref = "Warning: ")

Prints a warning message to STDERR

View source

.read_gzip(path, &) : Nil

Reads gziped file line by line

read_gzip(path) { |line| puts line }
View source

.read_gzip(path) : String

Reads gziped file into a string

View source

.read_yaml(file : String) : YAML::Any

Parses yaml from file and fails with message

View source

.run(cmd, args = EMPTY_STRING_ARRAY, msg = "cmd failed") : Nil

Runs a command using system and raises if command fails

View source

.string_md5sum(path) : String

Returns md5 digest for string

View source

.string_sha1sum(path) : String

Returns sha1 digest for string

View source

.string_sha256sum(path) : String

Returns sha256 digest for string

View source

.string_sha512sum(path) : String

Returns sha512 digest for string

View source

.string_to_file(str, file) : Nil

Writes String to a file

View source

.timer

Timer for a block of commands, prints time at the end Examples

timer { do_something }
View source

.write_binary_file(file : String, data : Bytes)

Writes Bytes to a file

View source

.write_gzip(str, path) : Nil

Writes gziped file from a string

View source