2011-03-31 06:32:47 +00:00
|
|
|
/*
|
|
|
|
* stores.js: Top-level include for all nconf stores
|
|
|
|
*
|
|
|
|
* (C) 2011, Charlie Robbins
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-05-14 05:47:26 +00:00
|
|
|
var fs = require('fs'),
|
|
|
|
stores = exports;
|
2011-03-31 06:32:47 +00:00
|
|
|
|
2011-04-02 08:31:20 +00:00
|
|
|
function capitalize (str) {
|
|
|
|
return str && str[0].toUpperCase() + str.slice(1);
|
|
|
|
};
|
|
|
|
|
2011-05-14 05:47:26 +00:00
|
|
|
//
|
|
|
|
// Setup all stores as lazy-loaded getters.
|
|
|
|
//
|
|
|
|
fs.readdirSync(__dirname + '/stores').forEach(function (file) {
|
|
|
|
var store = file.replace('.js', ''),
|
|
|
|
name = capitalize(store);
|
|
|
|
|
|
|
|
stores.__defineGetter__(name, function () {
|
|
|
|
return require('./stores/' + store)[name];
|
|
|
|
});
|
|
|
|
});
|
2011-04-02 08:31:20 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// ### function create (type, options)
|
|
|
|
// #### @type {string} Type of the nconf store to use.
|
|
|
|
// #### @options {Object} Options for the store instance.
|
|
|
|
// Creates a store of the specified `type` using the
|
|
|
|
// specified `options`.
|
|
|
|
//
|
|
|
|
stores.create = function (type, options) {
|
|
|
|
return new stores[capitalize(type.toLowerCase())](options);
|
|
|
|
};
|