filterMethod option (fn) to filter nested remote methods
This commit is contained in:
parent
42f938ed72
commit
097daf1deb
|
@ -502,9 +502,18 @@ Model.nestRemoting = function(relationName, options) {
|
||||||
var acceptArgs = [];
|
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) {
|
sharedToClass.methods().forEach(function(method) {
|
||||||
var matches;
|
var methodName;
|
||||||
if (!method.isStatic && (matches = method.name.match(regExp))) {
|
if (!method.isStatic && (methodName = filter(method, relation))) {
|
||||||
var prefix = relation.multiple ? '__findById__' : '__get__';
|
var prefix = relation.multiple ? '__findById__' : '__get__';
|
||||||
var getterName = options.getterName || (prefix + relationName);
|
var getterName = options.getterName || (prefix + relationName);
|
||||||
|
|
||||||
|
@ -519,7 +528,6 @@ Model.nestRemoting = function(relationName, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts = {};
|
var opts = {};
|
||||||
var methodName = '__' + matches[1] + '__' + relationName + '__' + matches[2];
|
|
||||||
|
|
||||||
opts.accepts = acceptArgs.concat(method.accepts || []);
|
opts.accepts = acceptArgs.concat(method.accepts || []);
|
||||||
opts.returns = [].concat(method.returns || []);
|
opts.returns = [].concat(method.returns || []);
|
||||||
|
|
Loading…
Reference in New Issue