Module: EasyConfig

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

Defined Under Namespace

Modules: Env, PathResolver Classes: ConfigFile, Configuration, ConfigurationNotFound, UnknownConfigPath

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.add_config_method(config) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/easy_config.rb', line 21

def self.add_config_method(config)
  (class << self; self; end).instance_eval do
    define_method config.name do
      config.configuration
    end
  end
end

.config_path=(path) ⇒ Object



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

def self.config_path=(path)
  EasyConfig::PathResolver.config_path = path
  self.reset!
end

.method_missing(name) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/easy_config.rb', line 5

def self.method_missing(name)
  unless @loaded
    setup_config
    self.send name
  else
    raise ConfigurationNotFound.new("Configuration for '#{name}' was not found.")
  end
end

.reset!Object



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

def self.reset!
  EasyConfig::ConfigFile.reset!
  @loaded = false
  setup_config
end

.setup_configObject



14
15
16
17
18
19
# File 'lib/easy_config.rb', line 14

def self.setup_config
  EasyConfig::ConfigFile.all.each do |f|
    add_config_method(f)
  end
  @loaded = true
end