Class: AppConfig::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/app-config.rb

Overview

Private: Actual configuration class. A new one of these is created whenever AppConfig is configured.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Private: Initialize the class with a filename and environment (optional). Takes a hash of options.

filename - configuration filename. Must exist. environment - optional, environment to pick in the configuration file.

Returns the new config.



23
24
25
26
27
28
29
30
# File 'lib/app-config.rb', line 23

def initialize(options)
  @options = options
  yaml = YAML.load(ERB.new(IO.read @options.config_file).result)
  yaml = yaml[@options.environment] if @options.environment
  @config = Hashie::Mash.new yaml
  @last_mtime = File.mtime @options.config_file
  @config
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Private: Override method_missing to access the config object. If the file has been modified and auto_reload is set to true, re-run initialize.

Returns the result of applying the method to the config object.



36
37
38
39
40
41
# File 'lib/app-config.rb', line 36

def method_missing(method, *args, &block)
  if @options.auto_reload and @last_mtime != File.mtime(@options.config_file)
    initialize @options
  end
  @config.__send__(method, *args, &block)
end