Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

api and doc change for indexzero/nconf#28 (`.file` may now take a str…

…ing instead of an object)

Conflicts:

	lib/nconf/provider.js
  • Loading branch information...
commit 6353d028f799cb3929df140207d6cf8ed20754b1 1 parent d3e6897
@jstewmon jstewmon authored jfhbrook committed
View
5 README.md
@@ -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.
``` 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.
View
24 lib/nconf/provider.js
@@ -29,14 +29,34 @@ var Provider = exports.Provider = function (options) {
// Define wrapper functions for using basic stores
// in this instance
//
-['argv', 'env', 'file'].forEach(function (type) {
+['argv', 'env'].forEach(function (type) {
Provider.prototype[type] = function (options) {
return this.add(type, options);
};
});
//
-// Define wrapper functions for using
+// 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
// overrides and defaults
//
['defaults', 'overrides'].forEach(function (type) {
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "nconf",
"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>",
"contributors": [
{ "name": "Charlie Robbins", "email": "charlie@nodejitsu.com" }
View
17 test/hierarchy-test.js
@@ -20,8 +20,21 @@ vows.describe('nconf/hierarchy').addBatch({
"When using nconf": {
"configured with two file stores": {
topic: function () {
- nconf.add('user', { type: 'file', file: userConfig })
- nconf.add('global', { type: 'file', file: globalConfig })
+ nconf.add('user', { type: 'file', file: userConfig });
+ 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();
return nconf;
},
Please sign in to comment.
Something went wrong with that request. Please try again.