Class: EnvironmentConfig
- Inherits:
-
Object
- Object
- EnvironmentConfig
- Includes:
- TypeFetcherMethods
- Defined in:
- lib/environment_config.rb,
lib/environment_config/types.rb,
lib/environment_config/builder.rb,
lib/environment_config/version.rb,
lib/environment_config/typed_env.rb,
lib/environment_config/types/json.rb,
lib/environment_config/types/yaml.rb,
lib/environment_config/types/string.rb,
lib/environment_config/types/symbol.rb,
lib/environment_config/types/boolean.rb,
lib/environment_config/types/integer.rb,
lib/environment_config/types/type_error.rb,
lib/environment_config/types/string_list.rb,
lib/environment_config/types/integer_list.rb,
lib/environment_config/type_fetcher_methods.rb
Defined Under Namespace
Modules: TypeFetcherMethods, Types Classes: Builder, TypedEnv
Constant Summary collapse
- VERSION =
'2.0.1'
Class Method Summary collapse
-
.ensure(&block) ⇒ Object
Accepts the same block as ‘load` does, but only validates the presence and type of environment variables.
-
.load(**options) {|builder| ... } ⇒ Object
Loads a configuration from environment variables as specified by the block given (using the environment config DSL).
Instance Method Summary collapse
-
#initialize ⇒ EnvironmentConfig
constructor
A new instance of EnvironmentConfig.
- #store(key, value) ⇒ Object
- #to_h ⇒ Object
- #to_string_hash ⇒ Object
- #to_symbol_hash ⇒ Object
Methods included from TypeFetcherMethods
Constructor Details
#initialize ⇒ EnvironmentConfig
Returns a new instance of EnvironmentConfig.
27 28 29 |
# File 'lib/environment_config.rb', line 27 def initialize @store = {} end |
Class Method Details
.ensure(&block) ⇒ Object
Accepts the same block as ‘load` does, but only validates the presence and type of environment variables. Does not return a configuration.
13 14 15 16 |
# File 'lib/environment_config.rb', line 13 def ensure(&block) load(&block) nil end |
.load(**options) {|builder| ... } ⇒ Object
Loads a configuration from environment variables as specified by the block given (using the environment config DSL)
20 21 22 23 24 |
# File 'lib/environment_config.rb', line 20 def load(**) builder = Builder.new(**) yield builder builder.config end |
Instance Method Details
#store(key, value) ⇒ Object
46 47 48 49 50 51 52 53 |
# 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 ⇒ Object
31 32 33 34 35 36 |
# 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 ⇒ Object
38 39 40 |
# File 'lib/environment_config.rb', line 38 def to_string_hash @store.dup end |
#to_symbol_hash ⇒ Object
42 43 44 |
# File 'lib/environment_config.rb', line 42 def to_symbol_hash @store.transform_keys(&:to_sym) end |