Module: Datadog::Core::Environment::VariableHelpers

Extended by:
VariableHelpers
Included in:
VariableHelpers
Defined in:
lib/datadog/core/environment/variable_helpers.rb

Overview

Defines helper methods for environment

Instance Method Summary collapse

Instance Method Details

#env_to_bool(var, default = nil, deprecation_warning: true) ⇒ Boolean, default

Reads an environment variable as a Boolean.

Parameters:

  • var (String)

    environment variable

  • var (Array<String>)

    list of environment variables

  • default (Boolean) (defaults to: nil)

    the default value if the keys in var are not present in the environment

  • deprecation_warning (Boolean) (defaults to: true)

    when var is a list, record a deprecation log when the first key in var is not used.

Returns:

  • (Boolean)

    if the environment value is the string true or 1

  • (default)

    if the environment value is not found



21
22
23
24
25
26
27
28
29
30
# File 'lib/datadog/core/environment/variable_helpers.rb', line 21

def env_to_bool(var, default = nil, deprecation_warning: true)
  var = decode_array(var, deprecation_warning)
  if var && ENV.key?(var)
    value = ENV[var].to_s.strip
    value.downcase!
    value == 'true' || value == '1' # rubocop:disable Style/MultipleComparison
  else
    default
  end
end