Skip to content

Instantly share code, notes, and snippets.

@pacovell
Created October 25, 2011 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pacovell/1311177 to your computer and use it in GitHub Desktop.
Save pacovell/1311177 to your computer and use it in GitHub Desktop.
Red in all controllers in the base dir and add them to the returned object
/**
Done. Controllers manager
Copyright (c) 2011 Done. Corporation
*/
var fs = require('fs'),
dispatch = require('dispatch'),
logger = require(process.cwd() + '/lib/loggers').get('controller');
var Controllers = function () {
var self = this,
path = process.cwd() + '/app/controllers';
self.router = new dispatch.Router();
fs.readdirSync(path).forEach(function (filename) {
var name = filename.split('_');
var controller;
// Skip controllers.js
if (name.length > 1) {
controller = require([path, filename].join('/'));
name = name[0];
self[name] = controller;
self.router.addResource(controller);
logger.debug('Loaded controller ' + controller.name);
}
});
};
module.exports = new Controllers();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment