filterMethod option (fn) to filter nested remote methods

This commit is contained in:
Fabien Franzen 2014-08-04 19:02:30 +02:00
parent 42f938ed72
commit 097daf1deb
1 changed files with 11 additions and 3 deletions

View File

@ -502,9 +502,18 @@ Model.nestRemoting = function(relationName, options) {
var acceptArgs = [];
}
// A method should return the method name to use, if it is to be
// included as a nested method - a falsy return value will skip.
var filter = options.filterMethod || function(method, relation) {
var matches = method.name.match(regExp);
if (matches) {
return '__' + matches[1] + '__' + relation.name + '__' + matches[2];
}
};
sharedToClass.methods().forEach(function(method) {
var matches;
if (!method.isStatic && (matches = method.name.match(regExp))) {
var methodName;
if (!method.isStatic && (methodName = filter(method, relation))) {
var prefix = relation.multiple ? '__findById__' : '__get__';
var getterName = options.getterName || (prefix + relationName);
@ -519,7 +528,6 @@ Model.nestRemoting = function(relationName, options) {
}
var opts = {};
var methodName = '__' + matches[1] + '__' + relationName + '__' + matches[2];
opts.accepts = acceptArgs.concat(method.accepts || []);
opts.returns = [].concat(method.returns || []);