[api] Improve the `.use()` method. Use the memory engine by default

master
indexzero 2011-04-02 19:17:04 -04:00
parent ac888dc5a2
commit 752bb980ac
4 changed files with 12 additions and 2 deletions

View File

@ -19,7 +19,9 @@ nconf.stores = require('nconf/stores');
// specified `type`.
//
nconf.use = function (type, options) {
nconf.store = new nconf.stores.create(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');

View File

@ -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;
};

View File

@ -17,6 +17,7 @@ var nconf = require('nconf');
//
var Memory = exports.Memory = function (options) {
options = options || {};
this.type = 'memory';
this.store = {};
this.mtimes = {};
};

View File

@ -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;