Module: PortAuthority::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/port-authority/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args, &_block) ⇒ Object



10
11
12
13
# File 'lib/port-authority/config.rb', line 10

def method_missing(name, *_args, &_block)
  return @_cfg[name.to_sym] if @_cfg[name.to_sym] != nil
  fail(NoMethodError, "unknown configuration section #{name}", caller)
end

Instance Attribute Details

#_cfgObject (readonly)

Returns the value of attribute _cfg.



8
9
10
# File 'lib/port-authority/config.rb', line 8

def _cfg
  @_cfg
end

Instance Method Details

#dumpObject



40
41
42
# File 'lib/port-authority/config.rb', line 40

def dump
  self._cfg
end

#load!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/port-authority/config.rb', line 15

def load!
  @_cfg = {
    debug: false,
    syslog: false,
    daemonize: false,
    etcd: {
      endpoints: ['http://localhost:2379'],
      timeout: 5
    },
    commands: {
      arping: `which arping`.chomp,
      arp: `which arp`.chomp,
      iproute: `which ip`.chomp
    }
  }
  files = ['/etc/port-authority.yaml', './etc/port-authority.yaml'].delete_if {|f| !File.exists?(f)}
  dir_files = Dir['/etc/port-authority.d/**.yaml'] + Dir['./etc/port-authority.d/**.yaml']
  files += dir_files
  return false if files.empty?
  files.each do |f|
    @_cfg = @_cfg.deep_merge(YAML.load_file(f))
  end
  true
end

#to_yamlObject



44
45
46
# File 'lib/port-authority/config.rb', line 44

def to_yaml
  self._cfg.to_yaml.to_s
end