X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=server%2Fconfiguration.js;h=bc05e6ebd669adb00dda21f3dafa184d86fac109;hb=09c26937aa9127e8c76a6aba1fcb958aa7b3ee09;hp=be89037208f9904afab89b042382a5549710831e;hpb=e4a325a48e094405456666e12989bf9cdb4e38b5;p=KiwiIRC.git diff --git a/server/configuration.js b/server/configuration.js index be89037..bc05e6e 100644 --- a/server/configuration.js +++ b/server/configuration.js @@ -1,12 +1,18 @@ -var fs = require('fs'); +var fs = require('fs'), + events = require('events'), + util = require('util'); var config_filename = 'config.js', config_dirs = ['/etc/kiwiirc/', __dirname + '/../'], environment = 'production', loaded_config = Object.create(null); +var Config = function () { + events.EventEmitter.call(this); +}; +util.inherits(Config, events.EventEmitter); -function loadConfig() { +Config.prototype.loadConfig = function () { var new_config, conf_filepath, i; @@ -39,23 +45,24 @@ function loadConfig() { if (new_config) { loaded_config = new_config; global.config = new_config[environment] || {}; + this.emit('loaded'); return loaded_config; } else { return false; } -} +}; -module.exports.setEnvironment = function (new_environment) { +Config.prototype.setEnvironment = function (new_environment) { environment = new_environment; }; // Get the current config. Optionally for a different environment than currently set -module.exports.get = function (specific_environment) { +Config.prototype.get = function (specific_environment) { specific_environment = specific_environment || environment; return loaded_config[specific_environment] || {}; }; -module.exports.loadConfig = loadConfig; +module.exports = new Config();