Module: ApiBrasil::Core::Env

Defined in:
lib/api_brasil/core/env.rb

Overview

Leitura da configuracao a partir das variaveis de ambiente.

Constant Summary collapse

VARS =

Variaveis de ambiente reconhecidas pela SDK.

{
  bearer_token: "APIBRASIL_BEARER_TOKEN",
  device_token: "APIBRASIL_DEVICE_TOKEN",
  secret_key: "APIBRASIL_SECRET_KEY",
  base_url: "APIBRASIL_BASE_URL"
}.freeze

Class Method Summary collapse

Class Method Details

.configHash{Symbol => String}

Le a configuracao das variaveis de ambiente (quando disponiveis). Valores passados explicitamente no construtor sempre tem prioridade.

Returns:

  • (Hash{Symbol => String})


21
22
23
24
25
26
# File 'lib/api_brasil/core/env.rb', line 21

def config
  VARS.each_with_object({}) do |(key, name), acc|
    value = read(name)
    acc[key] = value unless value.nil? || value.empty?
  end
end

.read(name) ⇒ String?

Returns:

  • (String, nil)


29
30
31
# File 'lib/api_brasil/core/env.rb', line 29

def read(name)
  ENV.fetch(name, nil)&.to_s
end