Class: Yacl::Loader::Env

Inherits:
Yacl::Loader show all
Defined in:
lib/yacl/loader/env.rb

Overview

Env loads a Configuration object from a hash, generally this would be ENV.

The keys in the hash may be filtered by a prefix. For instance if you had keys in the hash of :

MY_APP_OPTION_A => 'foo'
MY_APP_OPTION_B => 'bar'

And you wanted to have those loaded so they were accessible as option.a and option.b you would use Loader::Env like:

Example:

properties = Yacl::Loader::Env.new( ENV, 'MY_APP' ).properties
properties.option.a # => 'foo'
properties.option.b # => 'bar'

Defined Under Namespace

Classes: Error

Instance Attribute Summary

Attributes inherited from Yacl::Loader

#options

Instance Method Summary collapse

Methods inherited from Yacl::Loader

extract_path, mapify_key, #reference_properties

Constructor Details

#initialize(opts = {}) ⇒ Env

Create a new Env instance from the loaded options

opts - a hash of options:

:env => The environment has to pass in (default: ENV). required.
:prefix => the prefix to strip off of each key in the :env hash. required.

Raises:



28
29
30
31
32
33
# File 'lib/yacl/loader/env.rb', line 28

def initialize( opts = {} )
  super
  @env    = @options.fetch( :env, ENV )
  @prefix = @options.fetch( :prefix, nil )
  raise Error, "No environment variable prefix is given" unless @prefix
end

Instance Method Details

#propertiesObject

Public: return the Properties that are created from the environment hash.

Returns a Properties instance



38
39
40
# File 'lib/yacl/loader/env.rb', line 38

def properties
  load_properties( @env, @prefix )
end