* fixes #258 chainable .required() * fixes #258 use var instead of let for travis builds
This commit is contained in:
parent
bac910a6df
commit
3607767f90
3 changed files with 27 additions and 8 deletions
18
README.md
18
README.md
|
@ -180,6 +180,24 @@ Declares a set of string keys to be mandatory, and throw an error if any are mis
|
|||
nconf.required(['keya', 'keyb']);
|
||||
// Error: Missing required keys: keyb
|
||||
```
|
||||
You can also chain `.required()` calls when needed. for example when a configuration depends on another configuration store
|
||||
|
||||
```js
|
||||
config
|
||||
.argv()
|
||||
.env()
|
||||
.required([ 'STAGE']) //here you should have STAGE otherwise throw an error
|
||||
.file( 'stage', path.resolve( 'configs', 'stages', config.get( 'STAGE' ) + '.json' ) )
|
||||
.required([ 'OAUTH:redirectURL']) // here you should have OAUTH:redirectURL, otherwise throw an error
|
||||
.file( 'oauth', path.resolve( 'configs', 'oauth', config.get( 'OAUTH:MODE' ) + '.json' ) )
|
||||
.file( 'app', path.resolve( 'configs', 'app.json' ) )
|
||||
.required([ 'LOGS_MODE']) // here you should haveLOGS_MODE, otherwise throw an error
|
||||
.add( 'logs', {
|
||||
type: 'literal',
|
||||
store: require( path.resolve( 'configs', 'logs', config.get( 'LOGS_MODE' ) + '.js') )
|
||||
} )
|
||||
.defaults( defaults );
|
||||
```
|
||||
|
||||
## Storage Engines
|
||||
|
||||
|
|
|
@ -363,7 +363,7 @@ Provider.prototype.required = function (keys) {
|
|||
if (missing.length) {
|
||||
throw new Error('Missing required keys: ' + missing.join(', '));
|
||||
} else {
|
||||
return true;
|
||||
return this;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -48,9 +48,10 @@ vows.describe('nconf').addBatch({
|
|||
nconf.set('foo:bar:bazz', 'buzz');
|
||||
assert.throws(nconf.required.bind(nconf, ['missing', 'foo:bar:bazz']), Error);
|
||||
},
|
||||
"should return true if all required keys exist": function() {
|
||||
"should return the provider if all required keys exist": function() {
|
||||
var Provider = nconf.Provider;
|
||||
nconf.set('foo:bar:bazz', 'buzz');
|
||||
assert.isTrue(nconf.required(['foo:bar:bazz']));
|
||||
assert.isTrue(nconf.required(['foo:bar:bazz']) instanceof Provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,22 +119,22 @@ vows.describe('nconf').addBatch({
|
|||
"without a callback": {
|
||||
"should respond with the merged store": function () {
|
||||
assert.deepEqual(nconf.load(), {
|
||||
title: 'My specific title',
|
||||
title: 'My specific title',
|
||||
color: 'green',
|
||||
movie: 'Kill Bill'
|
||||
movie: 'Kill Bill'
|
||||
});
|
||||
}
|
||||
},
|
||||
"with a callback": {
|
||||
topic: function () {
|
||||
nconf.load(this.callback.bind(null, null));
|
||||
nconf.load(this.callback.bind(null, null));
|
||||
},
|
||||
"should respond with the merged store": function (ign, err, store) {
|
||||
assert.isNull(err);
|
||||
assert.deepEqual(store, {
|
||||
title: 'My specific title',
|
||||
title: 'My specific title',
|
||||
color: 'green',
|
||||
movie: 'Kill Bill'
|
||||
movie: 'Kill Bill'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue