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

Instance Method Details

#from_environmentself

Create a new instance of the class using values from the environment.

Returns:

  • (self)

    The new config object



58
59
60
61
# File 'lib/configsl/from_environment.rb', line 58

def from_environment
  params = FromEnvironment.configsl_load_params(self, defaults: true)
  new(params)
end

#from_environment_prefix(prefix) ⇒ Object

Set the prefix for environment variables.

Parameters:

  • prefix (String)

    The prefix for the environment variables.



51
52
53
# File 'lib/configsl/from_environment.rb', line 51

def from_environment_prefix(prefix)
  @from_environment_prefix = prefix
end

#option(name, opts = {}) ⇒ Object

Ensure each option has an environment variable defined.



64
65
66
67
# File 'lib/configsl/from_environment.rb', line 64

def option(name, opts = {})
  opts[:env_variable] ||= "#{@from_environment_prefix}#{name.to_s.upcase}"
  super
end