[fix] Ensure that all options are passed to Provider.prototype.add
in Provider.prototype.file
. Fixes #51
[doc] Update README.md and method documentation [dist] Remove vim comments
This commit is contained in:
parent
eeddb70f20
commit
7515f66572
4 changed files with 42 additions and 40 deletions
|
@ -88,7 +88,11 @@ A sane default for this could be:
|
|||
//
|
||||
// 4. Values in `config.json`
|
||||
//
|
||||
nconf.file({ file: 'config.json' });
|
||||
nconf.file({
|
||||
file: 'config.json',
|
||||
dir: 'search/from/here',
|
||||
search: true
|
||||
});
|
||||
|
||||
//
|
||||
// 5. Any default values
|
||||
|
|
|
@ -36,23 +36,29 @@ var Provider = exports.Provider = function (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'}
|
||||
// ### function file (key, path)
|
||||
// #### @key {string|Object} Fully qualified options, name of file store, or path.
|
||||
// #### @path {string} **Optional** Path to the file for `key`.
|
||||
// Adds a new `File` store to this instance. Accepts the following options
|
||||
//
|
||||
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';
|
||||
}
|
||||
// nconf.file({ file: '.jitsuconf', dir: process.env.HOME, search: true })
|
||||
// nconf.file('path/to/config/file')
|
||||
// nconf.file('userconfig', 'path/to/config/file')
|
||||
//
|
||||
Provider.prototype.file = function (key, path) {
|
||||
var options;
|
||||
|
||||
if (arguments.length == 1) {
|
||||
options = typeof key !== 'object'
|
||||
? { type: 'file', file: key }
|
||||
: key;
|
||||
key = 'file';
|
||||
}
|
||||
return this.add(key, {type: 'file', file: path});
|
||||
else {
|
||||
options = { type: 'file', file: path };
|
||||
}
|
||||
|
||||
return this.add(key, options);
|
||||
};
|
||||
|
||||
//
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
* complete-test.js: Complete test with multiple providers
|
||||
* complete-test.js: Complete test for multiple stores.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var fs = require('fs'),
|
||||
|
@ -10,21 +13,25 @@ var fs = require('fs'),
|
|||
data = require('./fixtures/data').data,
|
||||
helpers = require('./helpers');
|
||||
|
||||
var complete = helpers.fixture('complete.json');
|
||||
var completeTest = helpers.fixture('complete-test.json');
|
||||
var completeTest = helpers.fixture('complete-test.json'),
|
||||
complete = helpers.fixture('complete.json');
|
||||
|
||||
vows.describe('nconf').addBatch({
|
||||
vows.describe('nconf/multiple-stores').addBatch({
|
||||
"When using the nconf with multiple providers": {
|
||||
topic: function () {
|
||||
var that = this;
|
||||
helpers.cp(complete, completeTest, function () {
|
||||
nconf.env();
|
||||
nconf.file({file: completeTest});
|
||||
nconf.use('argv', {type: 'literal', store: data});
|
||||
nconf.file({ file: completeTest });
|
||||
nconf.use('argv', { type: 'literal', store: data });
|
||||
that.callback();
|
||||
});
|
||||
},
|
||||
|
||||
"should have the correct `stores`": function () {
|
||||
assert.isObject(nconf.stores.env);
|
||||
assert.isObject(nconf.stores.argv);
|
||||
assert.isObject(nconf.stores.file);
|
||||
},
|
||||
"env vars": {
|
||||
"are present": function () {
|
||||
Object.keys(process.env).forEach(function (key) {
|
||||
|
@ -32,12 +39,10 @@ vows.describe('nconf').addBatch({
|
|||
});
|
||||
}
|
||||
},
|
||||
|
||||
"json vars": {
|
||||
topic: function () {
|
||||
fs.readFile(complete, 'utf8', this.callback);
|
||||
},
|
||||
|
||||
"are present": function (err, data) {
|
||||
assert.isNull(err);
|
||||
data = JSON.parse(data);
|
||||
|
@ -46,7 +51,6 @@ vows.describe('nconf').addBatch({
|
|||
});
|
||||
}
|
||||
},
|
||||
|
||||
"literal vars": {
|
||||
"are present": function () {
|
||||
Object.keys(data).forEach(function (key) {
|
||||
|
@ -54,24 +58,20 @@ vows.describe('nconf').addBatch({
|
|||
});
|
||||
}
|
||||
},
|
||||
|
||||
"and saving *synchronously*": {
|
||||
topic: function () {
|
||||
nconf.set('weebls', 'stuff');
|
||||
return nconf.save();
|
||||
},
|
||||
|
||||
"correct return value": function (topic) {
|
||||
Object.keys(topic).forEach(function (key) {
|
||||
assert.deepEqual(topic[key], nconf.get(key));
|
||||
});
|
||||
},
|
||||
|
||||
"the file": {
|
||||
topic: function () {
|
||||
fs.readFile(completeTest, 'utf8', this.callback);
|
||||
},
|
||||
|
||||
"saved correctly": function (err, data) {
|
||||
data = JSON.parse(data);
|
||||
Object.keys(data).forEach(function (key) {
|
||||
|
@ -95,19 +95,16 @@ vows.describe('nconf').addBatch({
|
|||
nconf.set('weebls', 'crap');
|
||||
nconf.save(this.callback);
|
||||
},
|
||||
|
||||
"correct return value": function (err, data) {
|
||||
assert.isNull(err);
|
||||
Object.keys(data).forEach(function (key) {
|
||||
assert.deepEqual(data[key], nconf.get(key));
|
||||
});
|
||||
},
|
||||
|
||||
"the file": {
|
||||
topic: function () {
|
||||
fs.readFile(completeTest, 'utf8', this.callback);
|
||||
},
|
||||
|
||||
"saved correctly": function (err, data) {
|
||||
assert.isNull(err);
|
||||
data = JSON.parse(data);
|
||||
|
@ -118,7 +115,6 @@ vows.describe('nconf').addBatch({
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
teardown: function () {
|
||||
fs.unlinkSync(completeTest);
|
||||
nconf.remove('file');
|
||||
|
@ -127,6 +123,4 @@ vows.describe('nconf').addBatch({
|
|||
nconf.remove('env');
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
|
||||
// vim: ts=2 shiftwidth=2 softtabstop=2
|
||||
}).export(module);
|
|
@ -65,6 +65,4 @@ exports.cp = function (from, to, callback) {
|
|||
|
||||
exports.fixture = function (file) {
|
||||
return require('path').join(__dirname, 'fixtures', file);
|
||||
};
|
||||
|
||||
// vim: ts=2 shiftwidth=2 softtabstop=2
|
||||
};
|
Loading…
Reference in a new issue