Add app.utility to register utility functions by name

This commit is contained in:
Raymond Feng 2014-11-18 15:07:14 -08:00
parent 7c96aec9af
commit 087f353af1
2 changed files with 17 additions and 0 deletions

View File

@ -243,6 +243,21 @@ app.connector = function(name, connector) {
this.connectors[camelize(name)] = connector;
};
/**
* Register a utility function with the given name
*
* The utilities will be used to resolve functions by name so that functions can
* be referenced in JSON configuration files, for example, the default value
* function, the middleware handler, or the validator
* @param {String} name The utility name
* @param {Function} fn The handler
*/
app.utility = function(name, fn) {
assert(typeof name === 'string', 'Utility function name must be a string');
assert(typeof fn === 'function', 'The utility must be a function');
this.utilities[name] = fn;
};
/**
* Get all remote objects.
* @returns {Object} [Remote objects](http://apidocs.strongloop.com/strong-remoting/#remoteobjectsoptions).

View File

@ -75,6 +75,8 @@ function createApplication() {
app.connector('memory', loopback.Memory);
app.connector('remote', loopback.Remote);
app.utilities = {};
return app;
}