Module: ConfigSL::FromEnvironment::ClassMethods
- Defined in:
- lib/configsl/from_environment.rb
Overview
Class methods necessary for loading configuration from the environment.
Instance Method Summary collapse
-
#from_environment ⇒ self
Create a new instance of the class using values from the environment.
-
#from_environment_prefix(prefix) ⇒ Object
Set the prefix for environment variables.
-
#option(name, opts = {}) ⇒ Object
Ensure each option has an environment variable defined.
Instance Method Details
#from_environment ⇒ self
Create a new instance of the class using values from the environment.
36 37 38 39 40 41 42 |
# File 'lib/configsl/from_environment.rb', line 36 def from_environment params = .transform_values do |opts| ENV.fetch(opts[:env_variable], opts[:default]) end new(params) end |
#from_environment_prefix(prefix) ⇒ Object
Set the prefix for environment variables.
29 30 31 |
# File 'lib/configsl/from_environment.rb', line 29 def from_environment_prefix(prefix) @from_environment_prefix = prefix end |
#option(name, opts = {}) ⇒ Object
Ensure each option has an environment variable defined.
45 46 47 48 |
# File 'lib/configsl/from_environment.rb', line 45 def option(name, opts = {}) opts[:env_variable] ||= "#{@from_environment_prefix}#{name.to_s.upcase}" super end |