Defer to Utils#fetch for getting ENV state

This commit is contained in:
Andrew Stewart 2014-07-12 11:00:34 -07:00
parent ba295e9642
commit c4d03428e8
1 changed files with 2 additions and 33 deletions

View File

@ -8,39 +8,8 @@
'use strict';
// Public: Fetches a variable from the environment, returning a provided value if
// it's not set.
//
// variable - variable to fetch from the environment
// defaultValue - value to return if the ENV variable isn't set
//
// Examples
//
// process.env["CYLON_TEST"] #=> undefined
// fetch("CYLON_TEST", "not set")
// #=> "not set"
//
// process.env["CYLON_TEST"] #=> false
// fetch("CYLON_TEST", true)
// #=> false
//
// process.env["CYLON_TEST"] #=> true
// fetch("CYLON_TEST", false)
// #=> true
//
// Returns the env var or default value
var fetch = function(variable, defaultValue) {
if (defaultValue == null) {
defaultValue = false;
}
if (process.env[variable] != null) {
return process.env[variable];
} else {
return defaultValue;
}
};
var Utils = require('./utils');
module.exports = {
testing_mode: fetch('CYLON_TEST')
testing_mode: Utils.fetch(process.env, 'CYLON_TEST', false)
};