Class: ProxyMgr::Config

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

Defined Under Namespace

Modules: Validators Classes: ConfigException

Constant Summary collapse

DEFAULTS =
{
  'haproxy' => {
    'path'        => 'haproxy',
    'config_path' => '/etc/haproxy/haproxy.cfg',
    'socket_path' => '/var/lib/haproxy.sock',
    'global'      => ['maxconn 4096',
                      'log  127.0.0.1 local0',
                      'log  127.0.0.1 local1 notice'],
    'defaults'    => ['log global',
                      'option dontlognull',
                      'maxconn 2000',
                      'retries 3',
                      'timeout connect 5s',
                      'timeout client 1m',
                      'timeout server 1m',
                      'option redispatch',
                      'balance roundrobin']
  }
}
VALIDATORS =
{
  'haproxy' => {
    'path' => :executable,
    'config_path' => :fullpath,
    'socket_path' => :fullpath,
    'global'      => :array_of_strings,
    'default'     => :array_of_strings
  },
  'service_config' => {
    'type' => :svconfig
  }
}

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Config

Returns a new instance of Config.



39
40
41
42
43
44
45
# File 'lib/proxymgr/config.rb', line 39

def initialize(file)
  data    = ERB.new(File.read(file)).result(binding)
  @config = YAML.load(data) || {}

  merge_defaults!
  validate_config
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  @config[key]
end