Class: BlueprintConfig::Backend::ENV
- Defined in:
- lib/blueprint_config/backend/env.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #env_downcased ⇒ Object
- #env_downcased_keys ⇒ Object
- #filtered_env ⇒ Object
-
#initialize(options = {}) ⇒ ENV
constructor
A new instance of ENV.
- #load_keys ⇒ Object
- #source ⇒ Object
- #transformed_env ⇒ Object
Methods inherited from Base
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 = 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 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 { # env: ::ENV.to_h.transform_keys(&:to_sym), ** transformed_env } end |
#source ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/blueprint_config/backend/env.rb', line 46 def source details = [] details << "whitelist_keys: #{@options[:whitelist_keys].join(', ')}" if @options[:whitelist_keys] details << "whitelist_prefixes: #{@options[:whitelist_prefixes].join(', ')}" if @options[:whitelist_prefixes] if details.any? "#{self.class.name}(#{details.join(', ')})" else self.class.name end end |
#transformed_env ⇒ Object
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 |