Module: Envconfig::Provider
- Included in:
- Database::Generic, Memcached::Memcachier, Mongodb::Mongohq, Mongodb::Mongolab, Redis::Openredis, Redis::Rediscloud, Redis::Redisgreen, Redis::Redistogo, Smtp::Generic, Smtp::Mailgun, Smtp::Mandrill, Smtp::Postmark, Smtp::Sendgrid
- Defined in:
- lib/envconfig/provider.rb
Defined Under Namespace
Classes: NullProvider
Class Method Summary collapse
Instance Method Summary collapse
-
#config ⇒ Object
The configuration derived from the environment for this provider.
-
#env_keys ⇒ Object
Which ENV keys are used by this provider.
-
#filter_config(config) ⇒ Object
A hook for arbitrary changes to the config hash.
- #initialize(env) ⇒ Object
-
#mapping ⇒ Object
A mapping of configuration keys to environment keys.
- #name ⇒ Object
-
#static ⇒ Object
Static configuration which doesn’t vary by environment.
-
#valid? ⇒ Boolean
Whether the environment is valid for this provider.
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
#config ⇒ Object
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_keys ⇒ Object
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 |
#mapping ⇒ Object
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 |
#name ⇒ Object
29 30 31 |
# File 'lib/envconfig/provider.rb', line 29 def name self.class.name.split("::").last end |
#static ⇒ Object
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.
34 35 36 |
# File 'lib/envconfig/provider.rb', line 34 def valid? env_keys.all? { |k| env.key?(k) } end |