api and doc change for flatiron/nconf#28 (.file may now take a string instead of an object)

Conflicts:

	lib/nconf/provider.js
This commit is contained in:
Jonathan Stewmon 2012-03-02 12:59:06 -06:00 committed by Joshua Holbrook
parent d3e68976c8
commit 6353d028f7
4 changed files with 42 additions and 6 deletions

View file

@ -174,7 +174,10 @@ Loads a given object literal into the configuration hierarchy. Both `nconf.defau
Based on the Memory store, but provides additional methods `.save()` and `.load()` which allow you to read your configuration to and from file. As with the Memory store, all method calls are synchronous with the exception of `.save()` and `.load()` which take callback functions. It is important to note that setting keys in the File engine will not be persisted to disk until a call to `.save()` is made. Based on the Memory store, but provides additional methods `.save()` and `.load()` which allow you to read your configuration to and from file. As with the Memory store, all method calls are synchronous with the exception of `.save()` and `.load()` which take callback functions. It is important to note that setting keys in the File engine will not be persisted to disk until a call to `.save()` is made.
``` js ``` js
nconf.file({ file: 'path/to/your/config.json' }); nconf.file('path/to/your/config.json');
// add multiple files, hierarchically. notice the unique key for each file
nconf.file('user', 'path/to/your/user.json');
nconf.file('global', 'path/to/your/global.json');
``` ```
The file store is also extensible for multiple file formats, defaulting to `JSON`. To use a custom format, simply pass a format object to the `.use()` method. This object must have `.parse()` and `.stringify()` methods just like the native `JSON` object. The file store is also extensible for multiple file formats, defaulting to `JSON`. To use a custom format, simply pass a format object to the `.use()` method. This object must have `.parse()` and `.stringify()` methods just like the native `JSON` object.

View file

@ -29,12 +29,32 @@ var Provider = exports.Provider = function (options) {
// Define wrapper functions for using basic stores // Define wrapper functions for using basic stores
// in this instance // in this instance
// //
['argv', 'env', 'file'].forEach(function (type) { ['argv', 'env'].forEach(function (type) {
Provider.prototype[type] = function (options) { Provider.prototype[type] = function (options) {
return this.add(type, options); return this.add(type, options);
}; };
}); });
//
// Adds the file at `path` to the stores with `key`
// If key is not given, `file` will be used as the key
// For backward compatibility, an object can still be passed like {file: '/etc/foo.conf'}
//
Provider.prototype.file = function(key, path) {
var args = Array.prototype.slice.call(arguments, 0);
if(args.length == 1) {
if(typeof key === 'object'){
path = key.file;
}
else {
path = key;
key = 'file';
}
}
return this.add(key, {type: 'file', file: path});
};
// //
// Define wrapper functions for using // Define wrapper functions for using
// overrides and defaults // overrides and defaults

View file

@ -1,7 +1,7 @@
{ {
"name": "nconf", "name": "nconf",
"description": "Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging.", "description": "Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging.",
"version": "0.5.1", "version": "0.6.0",
"author": "Nodejitsu Inc. <info@nodejitsu.com>", "author": "Nodejitsu Inc. <info@nodejitsu.com>",
"contributors": [ "contributors": [
{ "name": "Charlie Robbins", "email": "charlie@nodejitsu.com" } { "name": "Charlie Robbins", "email": "charlie@nodejitsu.com" }

View file

@ -20,8 +20,21 @@ vows.describe('nconf/hierarchy').addBatch({
"When using nconf": { "When using nconf": {
"configured with two file stores": { "configured with two file stores": {
topic: function () { topic: function () {
nconf.add('user', { type: 'file', file: userConfig }) nconf.add('user', { type: 'file', file: userConfig });
nconf.add('global', { type: 'file', file: globalConfig }) nconf.add('global', { type: 'file', file: globalConfig });
nconf.load();
return nconf;
},
"should have the appropriate keys present": function () {
assert.equal(nconf.get('title'), 'My specific title');
assert.equal(nconf.get('color'), 'green');
assert.equal(nconf.get('movie'), 'Kill Bill');
}
},
"configured with two file stores using `file`": {
topic: function () {
nconf.file('user', userConfig);
nconf.file('global', globalConfig);
nconf.load(); nconf.load();
return nconf; return nconf;
}, },