Module: Config

Defined in:
lib/config.rb,
lib/config/version.rb

Overview

Configuration module

Author:

  • Edmundo Sanchez

Defined Under Namespace

Classes: Configuration, Error

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.env_variables(*variables) ⇒ Object

Read Environmental Variables and set configuration Note All values will be strings by definition

Parameters:

  • List (Array)

    of Environmental variables



41
42
43
44
45
46
# File 'lib/config.rb', line 41

def self.env_variables(*variables)
  variables.map! do |var|
    [var,ENV[var]]
  end
  self.set(Hash[*variables.flatten])
end

.getConfig

Get configuration

Returns:



11
12
13
# File 'lib/config.rb', line 11

def self.get
  @configuration ||= Configuration.new
end

.json_file(path) ⇒ Object

Read JSON file and set configuration

Parameters:

  • Absolute (String)

    Path to Yaml file



34
35
36
37
# File 'lib/config.rb', line 34

def self.json_file(path)
  file = File.read(path)
  self.set JSON.parse(file)
end

.resetObject

Reset the configuration to an empty Configuration object



24
25
26
# File 'lib/config.rb', line 24

def self.reset
  @configuration = Configuration.new
end

.set(config) ⇒ Object

Set Configuration with a block

Parameters:

  • Configuration (Hash)

    Hash



16
17
18
19
20
21
22
# File 'lib/config.rb', line 16

def self.set(config)
  @configuration = Configuration.new do |conf|
    config.each do |key,value|
      conf.instance_variable_set("@#{key}",value)
    end
  end
end

.yaml_file(path) ⇒ Object

Read YAML file and set configuration

Parameters:

  • Absolute (String)

    Path to Yaml file



29
30
31
# File 'lib/config.rb', line 29

def self.yaml_file(path)
  self.set YAML.load_file(path)
end