-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-description.js
34 lines (28 loc) · 968 Bytes
/
custom-description.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module.exports = function (Model, options) {
// get new descriptions from model json config
var descriptions = options.descriptions || {};
for (var methodName in descriptions) {
var newDescription = descriptions[methodName];
var method = findMethod(methodName);
if (method) {
method.description = newDescription; // apply new description
} else {
console.error("Mixin CustomDescription: %s.%s doesn't exist", Model.modelName, methodName); // can't find method
}
}
/**
* Find method from model
* @param {String} methodName
* @returns {SharedMethod}
*/
function findMethod(methodName) {
var methods = Model.sharedClass.methods()
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
if (method.name === methodName) {
return method;
}
}
return null;
}
};