2011-11-20 21:21:09 +00:00
|
|
|
/*
|
|
|
|
* env.js: Simple memory-based store for environment variables
|
|
|
|
*
|
2011-11-24 05:33:08 +00:00
|
|
|
* (C) 2011, Nodejitsu Inc.
|
2011-11-20 21:21:09 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
var util = require('util'),
|
|
|
|
Memory = require('./memory').Memory;
|
|
|
|
|
|
|
|
//
|
|
|
|
// ### function Env (options)
|
|
|
|
// #### @options {Object} Options for this instance.
|
|
|
|
// Constructor function for the Env nconf store, a simple abstraction
|
|
|
|
// around the Memory store that can read process environment variables.
|
|
|
|
//
|
|
|
|
var Env = exports.Env = function (options) {
|
|
|
|
Memory.call(this, options);
|
|
|
|
|
2011-11-21 01:00:04 +00:00
|
|
|
this.type = 'env';
|
|
|
|
this.readOnly = true;
|
|
|
|
this.options = options || [];
|
2011-11-20 21:21:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Inherit from the Memory store
|
|
|
|
util.inherits(Env, Memory);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ### function loadSync ()
|
|
|
|
// Loads the data passed in from `process.env` into this instance.
|
|
|
|
//
|
|
|
|
Env.prototype.loadSync = function () {
|
|
|
|
this.loadEnv();
|
|
|
|
return this.store;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// ### function loadEnv ()
|
|
|
|
// Loads the data passed in from `process.env` into this instance.
|
|
|
|
//
|
|
|
|
Env.prototype.loadEnv = function () {
|
|
|
|
var self = this;
|
|
|
|
|
2011-11-21 01:00:04 +00:00
|
|
|
this.readOnly = false;
|
2011-11-20 21:21:09 +00:00
|
|
|
Object.keys(process.env).filter(function (key) {
|
|
|
|
return !self.options.length || self.options.indexOf(key) !== -1;
|
|
|
|
}).forEach(function (key) {
|
|
|
|
self.set(key, process.env[key]);
|
|
|
|
});
|
2011-11-21 01:00:04 +00:00
|
|
|
|
|
|
|
this.readOnly = true;
|
2011-11-20 21:21:09 +00:00
|
|
|
return this.store;
|
|
|
|
};
|
|
|
|
|