Class: KStor::Config

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

Overview

Configuration items stored as YAML.

Constant Summary collapse

DEFAULTS =

Default values for configuration items.

They are used when loading configuration from a file, and for defining accessor methods.

{
  'database' => '/var/lib/kstor/kstor.sqlite',
  'socket' => '/run/kstor-server.socket',
  'nworkers' => 5,
  'session_idle_timeout' => 15 * 60,
  'session_life_timeout' => 4 * 60 * 60,
  'log_level' => 'warn'
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Config

Create configuration from hash data.

Parameters:

  • hash (Hash)

    configuration items



57
58
59
# File 'lib/kstor/config.rb', line 57

def initialize(hash)
  @data = DEFAULTS.merge(hash)
end

Instance Attribute Details

#databaseString (readonly)

Returns path to SQLite database file.

Returns:

  • (String)

    path to SQLite database file



27
28
29
30
31
32
33
34
# File 'lib/kstor/config.rb', line 27

DEFAULTS = {
  'database' => '/var/lib/kstor/kstor.sqlite',
  'socket' => '/run/kstor-server.socket',
  'nworkers' => 5,
  'session_idle_timeout' => 15 * 60,
  'session_life_timeout' => 4 * 60 * 60,
  'log_level' => 'warn'
}.freeze

#nworkersInteger (readonly)

Returns number of worker threads.

Returns:

  • (Integer)

    number of worker threads



27
28
29
30
31
32
33
34
# File 'lib/kstor/config.rb', line 27

DEFAULTS = {
  'database' => '/var/lib/kstor/kstor.sqlite',
  'socket' => '/run/kstor-server.socket',
  'nworkers' => 5,
  'session_idle_timeout' => 15 * 60,
  'session_life_timeout' => 4 * 60 * 60,
  'log_level' => 'warn'
}.freeze

#session_idle_timeoutInteger (readonly)

Returns seconds of inactivity before a session is closed.

Returns:

  • (Integer)

    seconds of inactivity before a session is closed



27
28
29
30
31
32
33
34
# File 'lib/kstor/config.rb', line 27

DEFAULTS = {
  'database' => '/var/lib/kstor/kstor.sqlite',
  'socket' => '/run/kstor-server.socket',
  'nworkers' => 5,
  'session_idle_timeout' => 15 * 60,
  'session_life_timeout' => 4 * 60 * 60,
  'log_level' => 'warn'
}.freeze

#session_life_timeoutInteger (readonly)

Returns seconds before a session is closed.

Returns:

  • (Integer)

    seconds before a session is closed



27
28
29
30
31
32
33
34
# File 'lib/kstor/config.rb', line 27

DEFAULTS = {
  'database' => '/var/lib/kstor/kstor.sqlite',
  'socket' => '/run/kstor-server.socket',
  'nworkers' => 5,
  'session_idle_timeout' => 15 * 60,
  'session_life_timeout' => 4 * 60 * 60,
  'log_level' => 'warn'
}.freeze

#socketString (readonly)

Returns path to KStor server listening socket.

Returns:

  • (String)

    path to KStor server listening socket



27
28
29
30
31
32
33
34
# File 'lib/kstor/config.rb', line 27

DEFAULTS = {
  'database' => '/var/lib/kstor/kstor.sqlite',
  'socket' => '/run/kstor-server.socket',
  'nworkers' => 5,
  'session_idle_timeout' => 15 * 60,
  'session_life_timeout' => 4 * 60 * 60,
  'log_level' => 'warn'
}.freeze

Class Method Details

.load(path) ⇒ KStor::Config

Load configuration from a file.

For each missing configuration item in file, use the default from DEFAULTS.

Parameters:

  • path (String)

    path to config file

Returns:



44
45
46
47
48
49
50
51
# File 'lib/kstor/config.rb', line 44

def load(path)
  hash = if path && File.file?(path)
           YAML.load_file(path)
         else
           {}
         end
  new(hash)
end