Class: Configuration

Inherits:
Hash
  • Object
show all
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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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



47
48
49
# File 'lib/configuration.rb', line 47

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

.defaultObject



43
44
45
# File 'lib/configuration.rb', line 43

def self.default
  build Defaults
end

.loadObject



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

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

      if File.file?(source) && File.readable?(source)
        loaded = YAML.load_file source
        if loaded.is_a?(Hash)
          h.merge! loaded
        end
      end

    end
  end
  build conf
end