[api dist] Begin to integrate features from reconf

master
indexzero 2011-08-22 20:17:28 -04:00
parent 57f0742455
commit add8922c04
3 changed files with 78 additions and 2 deletions

View File

@ -74,7 +74,7 @@ Provider.prototype.set = function (key, value, callback) {
//
Provider.prototype.merge = function (key, value, callback) {
return this.store.merge(key, value, callback);
}
};
//
// ### function clear (key, callback)
@ -101,7 +101,6 @@ Provider.prototype.load = function (callback) {
return this.store.loadSync();
}
if (!this.store.load) {
var error = new Error('nconf store ' + this.store.type + ' has no load() method');
if (callback) {

View File

@ -25,6 +25,7 @@ var File = exports.File = function (options) {
this.type = 'file';
this.file = options.file;
this.search = options.search || false;
this.format = options.format || {
stringify: function (obj) {
return JSON.stringify(obj, null, 2)
@ -140,4 +141,77 @@ File.prototype.loadSync = function () {
}
return data;
};
//
// ### function resolve (base)
// #### @base {string} Base directory (or file) to begin searching for the target file.
//
File.prototype.resolve = function (base) {
var looking = this.search,
fullpath,
stats;
if (this.file[0] === '/') {
//
// If filename for this instance is a fully qualified path
// (i.e. it starts with a `'/'`) then check if it exists
//
try {
stats = fs.statSync(fs.realpathSync(fullpath));
if (stats.isFile()) {
fullpath = this.file;
looking = false;
}
}
catch (ex) {
//
// Ignore errors
//
}
}
if (looking && base) {
//
// Attempt to stat the realpath located at `base`
// if the directory does not exist then return false.
//
try {
var stat = fs.statSync(fs.realpathSync(base));
looking = stat.isDirectory();
}
catch (ex) {
return false;
}
}
while (looking) {
try {
stats = fs.statSync(fs.realpathSync(fullpath = path.join(base, this.file)));
looking = stats.isDirectory();
}
catch (ex) {
var olddir = dir;
dir = path.dirname(dir);
if (olddir === dir) {
try {
var stat = fs.statSync(fs.realpathSync(configPath = path.join(process.env.HOME, filename)));
if(stat.isDirectory()) {
configPath = undefined;
}
}
catch (ex) {
//
// Ignore errors
//
configPath = undefined;
}
looking = false;
}
}
}
return fullpath;
};

View File

@ -12,6 +12,9 @@
"async": "0.1.x",
"pkginfo": "0.2.x"
},
"devDependencies": {
"vows": "0.5.x >=0.5.11"
},
"main": "./lib/nconf",
"scripts": { "test": "vows test/*-test.js --spec" },
"engines": { "node": ">= 0.4.0" }