Created
July 19, 2011 15:27
-
-
Save bcg/1092774 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
router = require('choreographer').router(); | |
Conductor = function() { | |
this.router = router; | |
this.services = []; | |
this.controllers = []; | |
this.requireEach('controllers', function(name, r) { | |
controller = new r.Controller(options); | |
this.addController(name, controller); | |
}); | |
this.requireEach('services', function(name, r) { | |
service = new r.Service(options); | |
this.addService(name, service); | |
}); | |
} | |
Conductor.prototype.requireEach = function(dir, callback) { | |
fs.readdir(__dirname + '/' + dir, function(err, files) { | |
file.forEach(function(file) { | |
var name = file.replace(/\.js$/,''); | |
s = require(__dirname + '/' + dir + '/' + name); | |
callback(name, s); | |
}); | |
}); | |
} | |
Conductor.prototype.addController = function(name, controller) { | |
this.controllers.append(controller); | |
} | |
Conductor.prototype.addService = function(name, service) { | |
this.services.append(service); | |
var ready_func = 'on'+name+'Ready' | |
for(var controller in this.controllers) { | |
if (typeof controller[ready_func] == 'function') { | |
service.on('ready', controller[ready_func]); | |
} | |
} | |
} | |
Conductor.prototype.router = function() { | |
return this.router; | |
} | |
exports.Conductor = Conductor; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment