Show:

Q.Config Class

Module: Q

Holds application config

Methods

clear

(
  • [keys=null]
)
Boolean

Clears the value of a field, removing that key from the tree

Parameters:

  • [keys=null] String | Array optional

    A key or an array of keys for traversing the configuration tree. If null, clears entire config.

Returns:

Boolean:

Returns whether the field to be cleared was found

clearOnServer

(
  • filename
  • [keys=null]
  • callback
  • [noSave=false]
)

Modify a config file by clearing some data Config file is searched in APP_DIR/files forder. If config server url is defined the filename is searched on config server

Parameters:

  • filename String

    The name of the config file. If config server is defined, file is changed there

  • [keys=null] String | Array optional

    A key or an array of keys for traversing the tree. If keys are not supplied the file is cleared If all-but-last keys point to plain array, last key is interpreted as a member of that array and only this array member is removed If all-but-last keys point to associative array (A) and last key is plain array (B) all keys from array A which are in array B are unset

  • callback Function

    Callback receives error as arguments

  • [noSave=false] Boolean optional

    if true the new tree is returned as callback second argument and not saved

expect

(
  • keys
)
Mixed

Gets the value of a configuration field. If it is null or not set, throws an exception. Otherwise, it is guaranteed to return a non-null value. May throw an exception if the config field is missing.

Parameters:

  • keys String | Array

    A key or an array of keys for traversing the configuration tree.

Returns:

Mixed:

Only returns non-null values

get

(
  • [keys=[]
  • [def=undefined]
)
Mixed

Gets the value of a configuration field

Parameters:

  • [keys=[] String | Array optional

    A key or an array of keys for traversing the configuration tree.

  • [def=undefined] Mixed optional

    The value to return if the field is not found. Defaults to undefined.

Returns:

Mixed:

The configuration field if it is found, otherwise def or undefined.

getAll

() Object

Gets the entire configuration tree

Returns:

getFromServer

(
  • filename
  • callback
)

Get contents of config file Config file is searched in APP_DIR/files forder. If config server url is defined the filename is searched on config server

Parameters:

  • filename String

    The name of the config file. If config server is defined, file is got from there

  • callback Function

    Callback receives error and Q.tree content as arguments

listen

(
  • callback
)

Start config server listener. Called from Q.Bootstrap.configure

Parameters:

load

(
  • filename
)

Loads a configuration file and merges it into the internal config.

Parameters:

  • filename String

    The filename of the file to load.

merge

(
  • second
)

Merges a configuration over the top of an existing configuration

Parameters:

  • second Q.Tree | Object

    The Object or Q.Tree to merge on top of the existing one

save

(
  • filename
  • [arrayPath=[]
  • [prefixPath=[]
  • [callback=null]
)

Saves the configuration to a file

Parameters:

  • filename String

    The filename to save into

  • [arrayPath=[] Array optional

    Array of keys identifying the path of the config to save

  • [prefixPath=[] Array optional

    Array of keys identifying the prefix path of the config to save

  • [callback=null] Function optional

serverInfo

() Mixed

Check for config server url and return it if found

Returns:

Mixed:

Config server information or false if config server is not defined (if called from 'Q/config' listener also returns false if config server itself is requested)

set

(
  • keys
  • value
)

Sets the value of a configuration field

Parameters:

  • keys String | Array

    A key or an array of keys for traversing the configuration tree.

  • value Mixed

    The value to set for that field.

setOnServer

(
  • filename
  • data
  • callback
  • [clear=false]
)

Modify a config file by merging over new data Config file is searched in APP_DIR/files forder. If config server url is defined the filename is searched on config server

Parameters:

  • filename String

    The name of the config file. If config server is defined, file is changed there

  • data Array

    The data to merge to the file

  • callback Function

    Callback receives error as arguments

  • [clear=false] Boolean optional

    Weather data shall be merged over or cleared and set