Permalink
Browse files

added App.call method

  • Loading branch information...
Grigore147 committed Jan 13, 2014
1 parent 4200326 commit 5615ae057141f5924c539af7882771a72f7cadad
Showing with 18 additions and 0 deletions.
  1. +18 −0 lib/katana.js
View
@@ -339,6 +339,24 @@ App.callMiddlewares = function(request, response, done) {
next(request, response);
}
+App.call = function(path) {
+ var segments = path.split('/');
+ var action = segments.pop();
+ var controller = this.controller(segments.join('/'));
+
+ var args = [].slice.call(arguments, 1);
+
+ if (!controller || typeof(controller[action])!=='function') {
+ var callback = typeof(args[args.length-1])==='function' ? args[args.length-1] : function(error) {
+ throw error;
+ }
+
+ return callback(new Error('controller '+ segments.join('/') +' has no method '+ action));
+ }
+
+ controller[action].apply(controller, args);
+}
+
setImmediate(function() {
Async.series({
stores: function(next) {

0 comments on commit 5615ae0

Please sign in to comment.