Sha256: dca12f110c80a0b52e862d8882043fedef0c1a57dd595cc4c0fb8e27a0bb919a

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# typed: false
module Datadog
  module Core
    # Namespace for handling application environment
    module Environment
      # Defines helper methods for environment
      module VariableHelpers
        extend self

        def env_to_bool(var, default = nil)
          var = decode_array(var)
          var && ENV.key?(var) ? ENV[var].to_s.strip.downcase == 'true' : default
        end

        def env_to_int(var, default = nil)
          var = decode_array(var)
          var && ENV.key?(var) ? ENV[var].to_i : default
        end

        def env_to_float(var, default = nil)
          var = decode_array(var)
          var && ENV.key?(var) ? ENV[var].to_f : default
        end

        def env_to_list(var, default = [])
          var = decode_array(var)
          if var && ENV.key?(var)
            ENV[var].split(',').map(&:strip)
          else
            default
          end
        end

        private

        def decode_array(var)
          var.is_a?(Array) ? var.find { |env_var| ENV.key?(env_var) } : var
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/datadog/core/environment/variable_helpers.rb
ddtrace-0.54.1 lib/datadog/core/environment/variable_helpers.rb
ddtrace-0.54.0 lib/datadog/core/environment/variable_helpers.rb
ddtrace-0.53.0 lib/datadog/core/environment/variable_helpers.rb
ddtrace-0.52.0 lib/datadog/core/environment/variable_helpers.rb