// --- Router
Router = Class({
/**
* Parameter hash.
*/
params: {},
/**
* Route match captures array.
*/
captures: [],
/**
* Route the given _request_, returning
* the value returned by Route#run()
*
* @param {object} request
* @return {mixed}
* @api private
*/
route: function(request){
this.request = request
return this.matchingRoute().run()
},
/**
* Attempt to match a route from Express.routes.
* Failure to do so will throw a NotFoundError.
*
* @return {Route}
* @api private
*/
matchingRoute: function(){
for (var i = 0, len = Express.routes.length; i < len; ++i)
if (this.match(Express.routes[i]))
return Express.routes[i]
throw new NotFoundError(this.request)
},
/**
* Check if _route_ matches the current request.
* If so populate #captures and #params.
*
* @param {object} route
* @return {bool}
* @api private
return true
}
},
/**
* Map #captures to #params.
*
* @api private
*/
mapParams: function() {
for (var i = 0, len = keys.length; i < len; ++i)
this.params[keys[i]] = this.captures[i+1]
}