Class: BlueprintConfig::Backend::ENV
- Inherits:
-
Base
- Object
- Base
- BlueprintConfig::Backend::ENV
show all
- Defined in:
- lib/blueprint_config/backend/env.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#fresh?, #nest_hash, #source
Constructor Details
#initialize(options = {}) ⇒ ENV
Returns a new instance of ENV.
10
11
12
|
# File 'lib/blueprint_config/backend/env.rb', line 10
def initialize(options = {})
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8
9
10
|
# File 'lib/blueprint_config/backend/env.rb', line 8
def options
@options
end
|
Instance Method Details
#env_downcased ⇒ Object
21
22
23
|
# File 'lib/blueprint_config/backend/env.rb', line 21
def env_downcased
@env_downcased ||= ::ENV.to_h.transform_keys(&:downcase)
end
|
#env_downcased_keys ⇒ Object
25
26
27
|
# File 'lib/blueprint_config/backend/env.rb', line 25
def env_downcased_keys
@env_downcased_keys ||= env_downcased.keys
end
|
#filtered_env ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/blueprint_config/backend/env.rb', line 29
def filtered_env
return env_downcased if @options[:allow_all]
allowed_keys = @options[:whitelist_keys]&.map(&:to_s) || []
@options[:whitelist_prefixes]&.each do |prefix|
allowed_keys += env_downcased_keys.select { |key| key.to_s.start_with?(prefix.to_s) }
end
env_downcased.slice(* allowed_keys)
end
|
#load_keys ⇒ Object
14
15
16
17
18
19
|
# File 'lib/blueprint_config/backend/env.rb', line 14
def load_keys
{
** transformed_env
}
end
|
40
41
42
43
44
|
# File 'lib/blueprint_config/backend/env.rb', line 40
def transformed_env
return filtered_env.transform_keys(&:to_sym) unless @options[:nest]
nest_hash(filtered_env, @options[:nest_separator] || '_')
end
|