Class: Configuration

Inherits:
Hash
  • Object
show all
Includes:
Logging
Defined in:
lib/configuration.rb

Constant Summary collapse

Defaults =
{
  'outgoing_call_dir' => '/var/spool/asterisk/outgoing',
  'archive_path'      => File.join(ENV['HOME'], 'facsimiles')
}
Sources =

Config files are read in this order

[
  '/etc/mailfakk2.yml',
  File.join( ENV['HOME'], '.mailfakk2.yml')
]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/configuration.rb', line 15

def method_missing(methname, *args, &block)
  methname = methname.to_s
  if has_key?(methname)
    self[methname]
  else
    if !block_given? && args.empty?
      raise NoMethodError, "unknown configuration field: #{methname}"
    else
      super
    end
  end
end

Class Method Details

.build(hash) ⇒ Object



49
50
51
# File 'lib/configuration.rb', line 49

def self.build(hash)
  new.update(Defaults).update(hash)
end

.defaultObject



45
46
47
# File 'lib/configuration.rb', line 45

def self.default
  build Defaults
end

.loadObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/configuration.rb', line 28

def self.load
  conf = returning(Defaults) do |h|
    Sources.each do |source|

      if File.file?(source) && File.readable?(source)
        log("loading config from #{source}")
        loaded = YAML.load_file source
        if loaded.is_a?(Hash)
          h.merge! loaded
        end
      end

    end
  end
  build conf
end