[api] Improve the .use()
method. Use the memory engine by default
This commit is contained in:
parent
ac888dc5a2
commit
752bb980ac
4 changed files with 12 additions and 2 deletions
|
@ -19,7 +19,9 @@ nconf.stores = require('nconf/stores');
|
|||
// specified `type`.
|
||||
//
|
||||
nconf.use = function (type, options) {
|
||||
if (!nconf.store || type.toLowerCase() !== nconf.store.type) {
|
||||
nconf.store = new nconf.stores.create(type, options);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -121,3 +123,8 @@ nconf.key = function () {
|
|||
nconf.path = function (key) {
|
||||
return key.split(':');
|
||||
};
|
||||
|
||||
//
|
||||
// Use the `memory` engine by default
|
||||
//
|
||||
nconf.use('memory');
|
||||
|
|
|
@ -22,6 +22,7 @@ var File = exports.File = function (options) {
|
|||
|
||||
Memory.call(this, options);
|
||||
|
||||
this.type = 'file';
|
||||
this.file = options.file;
|
||||
this.format = options.format || JSON;
|
||||
};
|
||||
|
|
|
@ -17,6 +17,7 @@ var nconf = require('nconf');
|
|||
//
|
||||
var Memory = exports.Memory = function (options) {
|
||||
options = options || {};
|
||||
this.type = 'memory';
|
||||
this.store = {};
|
||||
this.mtimes = {};
|
||||
};
|
||||
|
|
|
@ -23,7 +23,8 @@ var async = require('async'),
|
|||
// namespace:nested:key ==> 'value'
|
||||
//
|
||||
var Redis = exports.Redis = function (options) {
|
||||
options = options || {}
|
||||
options = options || {};
|
||||
this.type = 'redis';
|
||||
this.namespace = options.namespace || 'nconf';
|
||||
this.host = options.host || 'localhost';
|
||||
this.port = options.port || 6379;
|
||||
|
|
Loading…
Reference in a new issue