UNPKG

silentjs

Version:
38 lines (29 loc) 1.01 kB
// VENDOR LIBS var path = require('path'); var lodash = require('lodash'); // LIBS CORE var filesystem = require('lib-core/filesystem/filesystem'); // FRAMEWORK var configurationService = require('silentjs/configuration'); var Controller = require('silentjs/controller'); var ControllerStore = function (controllersPath) { this.controllers = {}; if (controllersPath) { this.loadControllers(controllersPath); } }; ControllerStore.prototype.addController = function (name, func) { this.controllers[name] = Controller.bind(this, func); }; ControllerStore.prototype.loadControllers = function (path) { var controllers = filesystem.getFileNamesIntoPath(path); lodash.each(controllers, function (controllerPath) { require(controllerPath); }); }; ControllerStore.prototype.getController = function (controllerId) { return lodash.find(this.controllers, function (controller, key) { return (controllerId === key); }); }; module.exports = ControllerStore;