Module: Config
- Defined in:
- lib/config.rb,
lib/config/version.rb
Overview
Configuration module
Defined Under Namespace
Classes: Configuration, Error
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.env_variables(*variables) ⇒ Object
Read Environmental Variables and set configuration Note All values will be strings by definition.
-
.get ⇒ Config
Get configuration.
-
.json_file(path) ⇒ Object
Read JSON file and set configuration.
-
.reset ⇒ Object
Reset the configuration to an empty Configuration object.
-
.set(config) ⇒ Object
Set Configuration with a block.
-
.yaml_file(path) ⇒ Object
Read YAML file and set configuration.
Class Method Details
.env_variables(*variables) ⇒ Object
Read Environmental Variables and set configuration Note All values will be strings by definition
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 |
.get ⇒ Config
Get configuration
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
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 |
.reset ⇒ Object
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
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
29 30 31 |
# File 'lib/config.rb', line 29 def self.yaml_file(path) self.set YAML.load_file(path) end |