class EnvironmentConfig
Constants
- VERSION
Public Class Methods
ensure(&block)
click to toggle source
Accepts the same block as `load` does, but only validates the presence and type of environment variables. Does not return a configuration.
# File lib/environment_config.rb, line 13 def ensure(&block) load(&block) nil end
load(**options) { |builder| ... }
click to toggle source
Loads a configuration from environment variables as specified by the block given (using the environment config DSL)
# File lib/environment_config.rb, line 20 def load(**options) builder = Builder.new(**options) yield builder builder.config end
new()
click to toggle source
# File lib/environment_config.rb, line 27 def initialize @store = {} end
Public Instance Methods
store(key, value)
click to toggle source
# File lib/environment_config.rb, line 46 def store(key, value) @store[key.to_s] = value define_accessor_method(key, value) return unless [true, false].include? value define_accessor_method("#{key}?", value) end
to_h()
click to toggle source
# File lib/environment_config.rb, line 31 def to_h # This method solely exists for purposes of "irb discoverability" raise NotImplementedError, 'Please choose between to_string_hash and to_symbol_hash, ' \ 'depending on the key type you want to get.' end
to_string_hash()
click to toggle source
# File lib/environment_config.rb, line 38 def to_string_hash @store.dup end
to_symbol_hash()
click to toggle source
# File lib/environment_config.rb, line 42 def to_symbol_hash @store.map { |k, v| [k.to_sym, v] }.to_h end
Private Instance Methods
define_accessor_method(name, value)
click to toggle source
# File lib/environment_config.rb, line 57 def define_accessor_method(name, value) define_singleton_method(name) { value } end