The Config Unit

libflitter/config/ConfigUnit

exports:  class ConfigUnit

class ConfigUnit

extends:  libflitter/Unit

The ConfigUnit initializes the dotenv package and loads config files from the specified directory, then makes them available under the Config context.

constructor(String config_directory = './config')

overrides:  super.constructor()         returns:  this

Creates an instance of the class. Also resolves the provided config_directory using the path package and stores it in this.directory.

go(express app, function next)

overrides:  super.go()         returns:  undefined

Initializes the dotenv package. Then, it recursively iterates over every file in this.directory and parses the name from the file, then imports that file and stores its config under that name. Then, it creates a global function to access the configuration by name and calls the next unit in the stack from within the Config context.

provides()

overrides:  super.provides()         returns:  Object

Returns an Object describing the services, templates, and directories provided by this unit. They are as follows:

Type Key Value Notes
Service Name name "config" The name of the service. This is added to the _flit.services array so other units can check for this unit.
Directory directories.config this.directory The fully-qualified path of the config files. This is added to the _flit.directories store so other units can access it.
Template templates.config Object Template that creates new config file in this.directory.

directory

type:  String

Set on initialization. Specifies the fully-qualified path of the configuration files to be processed. Each of these files should export an Object of key-value pairs that hold the configuration settings for that file. Each file's configuration is assigned a name based on the name of the file it was retrieved from. This includes sub-directories. As is convention in Flitter, sub-directories are delineated with a : character. So a config loaded from the file auth/Login.config.js would be named auth:Login.

Config Context

This context provides access to the configuration imported from the environment and config files. They can be accessed via the global config() function.

_flit.config

type:  Object

Stores the raw config objects, as well as the access function.

d

type: Object

Stores the raw config data imported from the configuration files. The configs are stored in key-value pairs where the key is the parsed name of the config, following the Flitter convention for sub-directory naming, and the values are the raw config Objects.

get(String accessor)

returns:  mixed

This function is used to access config values stored in _flit.config.d. The accessor string is a dot-separated reference to the config, which begins with the name of the config, which follows the Flitter standard convention for sub-directories. For example, the accessor auth:Messages.error.unavailable would retrieve the error.unavailable value from the file auth/Messages.config.js in the config directory.

global.config(String accessor)

Mapped to _flit.config.get.

No Comments
Back to top