Skip to content

Commit

Permalink
[api] Improve the .use() method. Use the memory engine by default
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Apr 2, 2011
1 parent ac888dc commit 752bb98
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/nconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

//
Expand Down Expand Up @@ -121,3 +123,8 @@ nconf.key = function () {
nconf.path = function (key) {
return key.split(':');
};

//
// Use the `memory` engine by default
//
nconf.use('memory');
1 change: 1 addition & 0 deletions lib/nconf/stores/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions lib/nconf/stores/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var nconf = require('nconf');
//
var Memory = exports.Memory = function (options) {
options = options || {};
this.type = 'memory';
this.store = {};
this.mtimes = {};
};
Expand Down
3 changes: 2 additions & 1 deletion lib/nconf/stores/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 752bb98

Please sign in to comment.