Home Manual Reference Source
import ConfigurationFile from 'projext/src/abstracts/configurationFile.js'
public class | version 1.0 | source

ConfigurationFile

A helper class for creating configuration files that can be overwritten on implementation.

Constructor Summary

Public Constructor
public abstract

constructor(pathUtils: PathUtils, overwritePaths: string | Array, asFactory: boolean, parentConfig: ConfigurationFile)

Class constructor.

Member Summary

Public Members
public

Whether the configuration should be created every time getConfig gets called or not.

public

A list of paths that can overwrite the configuration.

public

A parent configuration to extend.

public

A local reference for the pathUtils service.

Method Summary

Public Methods
public abstract

This method will be called the first time getConfig gets called (or every time, depending on the value of the asFactory property) and it should return the configuration contents.

public

This is the public method all other services uses to obtain the configuration.

Public Constructors

public abstract constructor(pathUtils: PathUtils, overwritePaths: string | Array, asFactory: boolean, parentConfig: ConfigurationFile) source

Class constructor.

Params:

NameTypeAttributeDescription
pathUtils PathUtils

To build the path to the overwrite file.

overwritePaths string | Array

A path of a list of paths for files that can overwrite the configuration. If used as a string, it will assume the path is inside the config folder, but if used as a list, the paths will be relative to the project root directory. If used as an array, the class will use the first file of the list that exists and ignore the rest.

asFactory boolean
  • optional
  • default: false

If true, every time getConfig gets called, the configuration will be created again, instead of caching it the first time it's created.

parentConfig ConfigurationFile
  • optional
  • default: null
  • nullable: true

If this parameter is used, the configuration created by the instance will be merged on top of the configuration returned by the getConfig method of the parent configuration.

Throw:

TypeError

If instantiated directly.

Public Members

public asFactory: boolean source

Whether the configuration should be created every time getConfig gets called or not.

public overwritePaths: Array source

A list of paths that can overwrite the configuration.

public parentConfig: ConfigurationFile source

A parent configuration to extend.

public pathUtils: PathUtils source

A local reference for the pathUtils service.

Public Methods

public abstract createConfig() source

This method will be called the first time getConfig gets called (or every time, depending on the value of the asFactory property) and it should return the configuration contents. As parameters, it will return the same ones sent to getConfig.

Throw:

Error

if not overwritten.

Example:

// Let's say the class receives this call: `getConfig({ name: 'Charito'}, 'hello')`, you could
// do something like this:
createConfig(options, prefix) {
  return { message: `${prefix} ${options.name}` };
}
// And the configuration would be `{ message: 'hello Charito'}`

public getConfig(args: Array): Object source

This is the public method all other services uses to obtain the configuration. If the configuration doesn't exists or asFactory was set to true on the constructor, the configuration will be reloaded.

Params:

NameTypeAttributeDescription
args Array

A list of parameters for the service to use when creating the configuration

Return:

Object