BiodbConfig: A class for storing configuration values.

BiodbConfigR Documentation

A class for storing configuration values.

Description

A class for storing configuration values.

A class for storing configuration values.

Details

This class is responsible for storing configuration. You must go through the single instance of this class to create and set and get configuration values. To get the single instance of this class, call the getConfig() method of class BiodbMain.

Methods

Public methods


Method new()

New instance initializer. No BiodbConfig object must not be created directly. Instead, access the config instance through the BiodbMain instance using the getConfig() method.

Usage
BiodbConfig$new(parent)
Arguments
parent

The BiodbMain instance.

Returns

Nothing.


Method getKeys()

Get the list of available keys.

Usage
BiodbConfig$getKeys(deprecated = FALSE)
Arguments
deprecated

If set to TRUE returns also the deprecated keys.

Returns

A character vector containing the config key names.


Method getTitle()

Get the title of a key.

Usage
BiodbConfig$getTitle(key)
Arguments
key

The name of a configuration key.

Returns

The title of the key as a character value.


Method getDescription()

Get the description of a key.

Usage
BiodbConfig$getDescription(key)
Arguments
key

The name of a configuration key.

Returns

The description of the key as a character value.


Method getDefaultValue()

Get the default value of a key.

Usage
BiodbConfig$getDefaultValue(key, as.chr = FALSE)
Arguments
key

The name of a configuration key.

as.chr

If set to TRUE, returns the value as character.

Returns

The default value for that key.


Method hasKey()

Test if a key exists.

Usage
BiodbConfig$hasKey(key)
Arguments
key

The name of a configuration key.

Returns

TRUE if a key with this name exists, FALSE otherwise.


Method isDefined()

Test if a key is defined (i.e.: if a value exists for this key).

Usage
BiodbConfig$isDefined(key, fail = TRUE)
Arguments
key

The name of a configuration key.

fail

If set to TRUE and the configuration key does not exist, then an error will be raised.

Returns

TRUE if the key has a value, FALSE otherwise.


Method isEnabled()

Test if a boolean key is set to TRUE. This method will raise an error if the key is not a boolean key.

Usage
BiodbConfig$isEnabled(key)
Arguments
key

The name of a configuration key.

Returns

TRUE if the boolean key has a value set to TRUE, FALSE otherwise.


Method get()

Get the value of a key.

Usage
BiodbConfig$get(key)
Arguments
key

The name of a configuration key.

Returns

The value associated with the key.


Method set()

Set the value of a key.

Usage
BiodbConfig$set(key, value)
Arguments
key

The name of a configuration key.

value

A value to associate with the key.

Returns

Nothing.


Method reset()

Reset the value of a key.

Usage
BiodbConfig$reset(key = NULL)
Arguments
key

The name of a configuration key. If NULL, all keys will be reset.

Returns

Nothing.


Method enable()

Set a boolean key to TRUE.

Usage
BiodbConfig$enable(key)
Arguments
key

The name of a configuration key.

Returns

Nothing.


Method disable()

Set a boolean key to FALSE.

Usage
BiodbConfig$disable(key)
Arguments
key

The name of a configuration key.

Returns

Nothing.


Method print()

Print list of configuration keys and their values.

Usage
BiodbConfig$print()
Returns

Nothing.


Method listKeys()

Get the full list of keys as a data frame.

Usage
BiodbConfig$listKeys()
Returns

A data frame containing keys, titles, types, and default values.


Method getAssocEnvVar()

Returns the environment variable associated with this configuration key.

Usage
BiodbConfig$getAssocEnvVar(key)
Arguments
key

The name of a configuration key.

Returns

The environment variable's value.


Method define()

Defines config properties from a structured object, normally loaded from a YAML file.

Usage
BiodbConfig$define(def)
Arguments
def

The list of key definitions.

Returns

Nothing.


Method notifyNewObservers()

Called by BiodbMain when a new observer is registered.

Usage
BiodbConfig$notifyNewObservers(obs)
Arguments
obs

The new observers registered by the BiodbMain instance.

Returns

Nothing.


Method terminate()

Terminates the instance. This method will be called automatically by the BiodbMain instance when you call

Usage
BiodbConfig$terminate()
Arguments
BiodbMain

:terminate().

Returns

Nothing.


Method clone()

The objects of this class are cloneable with this method.

Usage
BiodbConfig$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

BiodbMain.

Examples

# Create an instance with default settings:
mybiodb <- biodb::newInst()

# Get the config instance:
config <- mybiodb$getConfig()

# Print all available keys
config$getKeys()

# Get a configuration value:
value <- config$get('cache.directory')

# Set a configuration value:
config$set('dwnld.timeout', 600)

# For boolean values, you can use boolean methods:
config$get('offline')
config$enable('offline')    # set to TRUE
config$disable('offline')   # set to FALSE
config$isEnabled('offline')

# Terminate instance.
mybiodb$terminate()


pkrog/biodb documentation built on Nov. 29, 2022, 4:24 a.m.