Sha256: 207d4b33fd8427bea6a9aa00de6d993fc30a8de943d7df058c31b7bb53110308

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Datadog
  module Core
    # Namespace for handling application environment
    module Environment
      # Defines helper methods for environment
      module VariableHelpers
        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

2 entries across 2 versions & 1 rubygems

Version Path
ddtrace-0.51.1 lib/datadog/core/environment/variable_helpers.rb
ddtrace-0.51.0 lib/datadog/core/environment/variable_helpers.rb