Module: Envconfig::Provider

Defined Under Namespace

Classes: NullProvider

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(env, providers) ⇒ Object



4
5
6
7
# File 'lib/envconfig/provider.rb', line 4

def self.find(env, providers)
  providers.map { |k| k.new(env) }.detect(&:valid?) ||
    NullProvider.new
end

Instance Method Details

#configObject

The configuration derived from the environment for this provider.



44
45
46
# File 'lib/envconfig/provider.rb', line 44

def config
  filter_config(static.merge(dynamic))
end

#env_keysObject

Which ENV keys are used by this provider.



39
40
41
# File 'lib/envconfig/provider.rb', line 39

def env_keys
  mapping.values
end

#filter_config(config) ⇒ Object

A hook for arbitrary changes to the config hash.



49
50
51
# File 'lib/envconfig/provider.rb', line 49

def filter_config(config)
  config
end

#initialize(env) ⇒ Object



9
10
11
# File 'lib/envconfig/provider.rb', line 9

def initialize(env)
  @env = env
end

#mappingObject

A mapping of configuration keys to environment keys. e.g.

address: "PROVIDER_HOSTNAME",
password: "PROVIDER_API_KEY",



19
20
21
# File 'lib/envconfig/provider.rb', line 19

def mapping
  raise "Mapping must be implemented by subclass."
end

#nameObject



29
30
31
# File 'lib/envconfig/provider.rb', line 29

def name
  self.class.name.split("::").last
end

#staticObject

Static configuration which doesn’t vary by environment. e.g. hostname / port.



25
26
27
# File 'lib/envconfig/provider.rb', line 25

def static
  {}
end

#valid?Boolean

Whether the environment is valid for this provider.

Returns:



34
35
36
# File 'lib/envconfig/provider.rb', line 34

def valid?
  env_keys.all? { |k| env.key?(k) }
end