Prerequisites Gem

A ruby gem to make it easy to test that a set of prerequisite conditions are in place.

This can be useful when using ruby as 'glue' code for sysadmin or other tasks.

Installation

gem install prerequisites

Or add to your Gemfile:

gem "prerequisites"

Usage

This example checks that:

NB: You should ensure that any commands you list in the shell_commands section have no side-effects. These are supposed to be pre-flight checks.

config = {
  environment_variables: [
    "FOO",
    "BAR",
    { "BAZ" => "whatever" }
  ],
  executables_in_path: [
    "grep",
    "git",
    "kubectl"
  ],
  shell_commands: [
    "echo whatever | grep what",
    "kubectl config current-context | grep myk8scluster"
  ]
}

Prerequisites.new(config).check

If any of these conditions are not met, the code will raise an error of class:

…depending on the problem.