Class: Envyable::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/envyable/loader.rb

Overview

Internal: Loads yaml files into ENV (or a supplied hash).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, loadable = ENV) ⇒ Loader

Internal: initalize a Loader

path - a Pathname or String that describes where the yaml file

resides.

loadable - a Hash or hashlike structure that the yaml file variables

should be loaded into (default: ENV).


16
17
18
19
# File 'lib/envyable/loader.rb', line 16

def initialize(path, loadable = ENV)
  @path = path
  @loadable = loadable
end

Instance Attribute Details

#loadableObject (readonly)

Internal: Returns the Hash loadable of the loader



8
9
10
# File 'lib/envyable/loader.rb', line 8

def loadable
  @loadable
end

#pathObject (readonly)

Internal: Returns the String or Pathname path of the loader



5
6
7
# File 'lib/envyable/loader.rb', line 5

def path
  @path
end

Instance Method Details

#load(environment = 'development') ⇒ Object

Internal: perform the loading from the given environment

environment - a String describing the environment from which to load the

variables (default: development).

Examples

load(‘production’)

Returns nothing.



31
32
33
34
35
36
37
38
# File 'lib/envyable/loader.rb', line 31

def load(environment = 'development')
  if @yml ||= load_yml
    @yml.each { |key, value| set_value(key, value) }
    if @yml[environment]
      @yml[environment].each { |key, value| set_value(key, value) }
    end
  end
end