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



36
37
38
39
40
41
42
# File 'lib/configsl/from_environment.rb', line 36

def from_environment
  params = options.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.

Parameters:

  • prefix (String)

    The prefix for the 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