Class: Precursor::EnvVault

Inherits:
Vault
  • Object
show all
Defined in:
lib/env_vault.rb

Overview

Vault that provides config values from environment variables

Instance Method Summary collapse

Methods inherited from Vault

#key?, #value

Constructor Details

#initialize(separator: '__', allow_list: []) ⇒ EnvVault

Initializes new instance of [EnvVault]

Parameters:

  • separator (String) (defaults to: '__')

    separator for hierarchical config entries

  • allow_list (Array<String>) (defaults to: [])

    list of allowed env vars to prevent leaking of sensitive or unrelated vars



11
12
13
14
15
16
17
18
19
# File 'lib/env_vault.rb', line 11

def initialize(separator: '__', allow_list: [])
  @separator = '__'

  allow_set = Set.new(allow_list)

  @env_vars = ENV.select { |n, _| allow_set.empty? || allow_set.include?(n) }.to_h do |name, value|
    [name.sub(@separator, '.').to_sym, value]
  end
end