Class: ICFS::Web::Config Abstract

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

Overview

This class is abstract.

Configuration storage interface

Direct Known Subclasses

ConfigRedis, ConfigS3

Constant Summary collapse

ValConfig =

Valid config options

{
  method: :hash,
  optional: {
    'tz' => {
      method: :string,
      valid: /[+\-](0[0-9]|1[0-2]):[0-5][0-9]/.freeze,
      whitelist: true,
    }
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defaults = {}) ⇒ Config

New instance

Parameters:

  • defaults (Hash) (defaults to: {})

    The default options



41
42
43
44
45
# File 'lib/icfs/web/config.rb', line 41

def initialize(defaults={})
  @data = {}
  @unam = nil
  @defaults = defaults
end

Instance Attribute Details

#dataObject

The configuration values hash



51
52
53
# File 'lib/icfs/web/config.rb', line 51

def data
  @data
end

#defaultsObject (readonly)

The configuration defaults



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

def defaults
  @defaults
end

Instance Method Details

#get(key) ⇒ Object

Get a value

Parameters:

  • key (String)

    The name of the config setting



65
66
67
# File 'lib/icfs/web/config.rb', line 65

def get(key)
  @data.key?(key) ? @data[key] : @defaults[key]
end

#load(unam) ⇒ Boolean

Load a user configuration

Parameters:

  • unam (String)

    the user name to load

Returns:

  • (Boolean)

    if any config data was found for the user

Raises:

  • (NotImplementedError)


96
# File 'lib/icfs/web/config.rb', line 96

def load(unam); raise NotImplementedError; end

#saveObject

Save a user configuration

Raises:

  • (NotImplementedError)


102
# File 'lib/icfs/web/config.rb', line 102

def save; raise NotImplementedError; end

#set(key, val) ⇒ Object

Set a value

Parameters:

  • key (String)

    The name of the config setting

  • val (Object)

    The value of the config setting



76
77
78
# File 'lib/icfs/web/config.rb', line 76

def set(key, val)
  @data[key] = val
end