Module: EnvironmentHelpers::BooleanHelpers

Included in:
EnvironmentHelpers
Defined in:
lib/environment_helpers/boolean_helpers.rb

Constant Summary collapse

BOOLEAN_VALUES =
[true, false, nil].to_set

Instance Method Summary collapse

Instance Method Details

#boolean(name, default: nil, required: false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/environment_helpers/boolean_helpers.rb', line 5

def boolean(name, default: nil, required: false)
  check_default_value(:boolean, default, allow: BOOLEAN_VALUES)
  text = fetch_value(name, required: required)

  return true if truthy_text?(text)
  return false if falsey_text?(text)

  return default unless required
  fail(InvalidBooleanText, "Required boolean environment variable #{name} had inappropriate content '#{text}'")
end