Skip to content

Commit

Permalink
ability to run callbacks after each layer
Browse files Browse the repository at this point in the history
  • Loading branch information
parisholley committed Sep 14, 2012
1 parent cde68c1 commit c963de8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = function(server, options) {
_.defaults(options, defaults);

var layers = options.layers || getLayers(options.rootPath),
excludePrefix = options.excludePrefix;
excludePrefix = options.excludePrefix,
callbacks = options.callbacks || {};

layers.forEach(function(layer) {
server[layer] = loadComponents(options.rootPath + "/" + layer, layer);
Expand Down Expand Up @@ -81,6 +82,10 @@ module.exports = function(server, options) {
}
});

if(callbacks[layer]){
callbacks[layer]();
}

return components;
}

Expand Down
19 changes: 19 additions & 0 deletions test/LayersTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,22 @@ test("Ensure loader loads layers", function(t) {
t.equal(server.services.testService.testServiceFunction(), "A Test value", "Test service function is present and returns correct value");
t.end();
});

test("test layer callback", function(t) {
var layers = require('../layers'),
server = {};

var called = false;

layers(server, {
rootPath: __dirname + "/../testLayers",
callbacks: {
controllers: function(){
called = true;
}
}
});

t.ok(called, "Callback was hit");
t.end();
});

0 comments on commit c963de8

Please sign in to comment.