Class: Jerakia::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Config

Returns a new instance of Config


13
14
15
16
17
18
# File 'lib/jerakia/config.rb', line 13

def initialize(config = {})
  config_with_defaults = defaults.merge(config)
  @policydir = config_with_defaults['policydir']
  @server_url = config_with_defaults['server_url']
  @configdata = config_with_defaults
end

Instance Attribute Details

#policydirObject (readonly)

Returns the value of attribute policydir


4
5
6
# File 'lib/jerakia/config.rb', line 4

def policydir
  @policydir
end

#server_urlObject (readonly)

Returns the value of attribute server_url


5
6
7
# File 'lib/jerakia/config.rb', line 5

def server_url
  @server_url
end

Class Method Details

.load_from_file(file = '/etc/jerakia/jerakia.yaml') ⇒ Object


7
8
9
10
11
# File 'lib/jerakia/config.rb', line 7

def self.load_from_file(file = '/etc/jerakia/jerakia.yaml')
  new YAML.load_file(file)
rescue Psych::SyntaxError => e
  raise Jerakia::FileParseError, "Could not parse config file #{file}, #{e.message}"
end

Instance Method Details

#[](key) ⇒ Object


37
38
39
# File 'lib/jerakia/config.rb', line 37

def [](key)
  @configdata[key.to_s]
end

#defaultsObject


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jerakia/config.rb', line 20

def defaults
  {
    'policydir'     => '/etc/jerakia/policy.d',
    'plugindir'     => '/var/lib/jerakia/plugins',
    'logfile'       => '/var/log/jerakia/jerakia.log',
    'databasedir'   => '/var/db/jerakia',
    'loglevel'      => 'info',
    'vardir'        => '/var/lib/jerakia',
    'piddir'        => '/var/run',
    'enable_schema' => true,
  }
end

#to_hashObject


33
34
35
# File 'lib/jerakia/config.rb', line 33

def to_hash
  @configdata
end