2016-09-13 19:35:20 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../../server/config'),
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils = {};
|
|
|
|
|
|
|
|
configUtils.config = config;
|
|
|
|
configUtils.defaultConfig = _.cloneDeep(config.get());
|
|
|
|
|
2016-09-13 19:35:20 +03:00
|
|
|
/**
|
|
|
|
* configUtils.set({});
|
|
|
|
* configUtils.set('key', 'value');
|
|
|
|
*/
|
|
|
|
configUtils.set = function () {
|
|
|
|
var key = arguments[0],
|
|
|
|
value = arguments[1];
|
|
|
|
|
|
|
|
if (_.isObject(key)) {
|
|
|
|
_.each(key, function (value, key) {
|
|
|
|
config.set(key, value);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
config.set(key, value);
|
|
|
|
}
|
2015-12-14 23:05:11 +03:00
|
|
|
};
|
|
|
|
|
2016-09-13 19:35:20 +03:00
|
|
|
/**
|
|
|
|
* important: do not delete cloneDeep for value
|
|
|
|
* nconf keeps this as a reference and then it can happen that the defaultConfig get's overridden by new values
|
|
|
|
*/
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.restore = function () {
|
2016-09-13 19:35:20 +03:00
|
|
|
_.each(configUtils.defaultConfig, function (value, key) {
|
|
|
|
config.set(key, _.cloneDeep(value));
|
2015-12-14 23:05:11 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = configUtils;
|