Guest User

Untitled

a guest
Dec 17th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. module.exports = function(app) {
  2. app.models().forEach(Model => {
  3. const original = Model.sharedClass.methods;
  4. // Iterate over each model remote method
  5. Model.sharedClass.methods = () =>
  6. original.call(Model.sharedClass).map(overwriteMethodProperties);
  7. });
  8. app.emit('modelRemoted');
  9. };
  10.  
  11. function overwriteMethodProperties(method) {
  12. // Use the longer description for the 'notes' and just use the method name for the 'description'
  13. method.originalDescription = method.originalDescription || method.description;
  14. method.notes = method.originalDescription;
  15. method.description = methodDescription(method);
  16. return method;
  17. }
  18.  
  19. function methodDescription(method) {
  20. // Handle related methods by stripping out the __s
  21. let name = method.name
  22. .replace(/__(.+)__/, '$1 ')
  23. .replace(/([A-Z])/g, ' $1')
  24. .toLowerCase();
  25. return name
  26. .slice(0, 1)
  27. .toUpperCase()
  28. .concat(name.slice(1));
  29. }
Add Comment
Please, Sign In to add comment