-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api test] Updated test/provider-test.js and associated merge impleme…
…ntation
- Loading branch information
Showing
10 changed files
with
245 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* utils.js: Utility functions for the nconf module. | ||
* | ||
* (C) 2011, Charlie Robbins | ||
* | ||
*/ | ||
|
||
var fs = require('fs'), | ||
async = require('async'), | ||
formats = require('./formats'), | ||
stores = require('./stores'); | ||
|
||
var common = exports; | ||
|
||
// | ||
// ### function loadFiles (files) | ||
// #### @files {Object|Array} List of files (or settings object) to load. | ||
// #### @callback {function} Continuation to respond to when complete. | ||
// Loads all the data in the specified `files`. | ||
// | ||
common.loadFiles = function (files, callback) { | ||
if (!files) { | ||
return callback(null, {}); | ||
} | ||
|
||
var options = Array.isArray(files) ? { files: files } : files, | ||
store = new stores.Memory(); | ||
|
||
// | ||
// Set the default JSON format if not already | ||
// specified | ||
// | ||
options.format = options.format || formats.json; | ||
|
||
function loadFile (file, next) { | ||
fs.readFile(file, function (err, data) { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
data = options.format.parse(data.toString()); | ||
Object.keys(data).forEach(function (key) { | ||
store.merge(key, data[key]); | ||
}); | ||
|
||
next(); | ||
}); | ||
} | ||
|
||
async.forEach(files, loadFile, function (err) { | ||
return err ? callback(err) : callback(null, store.store); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* formats.js: Default formats supported by nconf | ||
* | ||
* (C) 2011, Charlie Robbins | ||
* | ||
*/ | ||
|
||
var ini = require('ini'); | ||
|
||
var formats = exports; | ||
|
||
// | ||
// ### @json | ||
// Standard JSON format which pretty prints `.stringify()`. | ||
// | ||
formats.json = { | ||
stringify: function (obj) { | ||
return JSON.stringify(obj, null, 2) | ||
}, | ||
parse: JSON.parse | ||
}; | ||
|
||
// | ||
// ### @ini | ||
// Standard INI format supplied from the `ini` module | ||
// http://en.wikipedia.org/wiki/INI_file | ||
// | ||
formats.ini = ini; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"apples": true, | ||
"bananas": true, | ||
"candy": { | ||
"something1": true, | ||
"something2": true | ||
} | ||
} |
Oops, something went wrong.