Last active
December 15, 2017 05:02
-
-
Save zbarbuto/b2feb5ec35578f5cfeeb905e13845317 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(app) { | |
app.models().forEach(Model => { | |
const original = Model.sharedClass.methods; | |
// Iterate over each model remote method | |
Model.sharedClass.methods = () => | |
original.call(Model.sharedClass).map(overwriteMethodProperties); | |
}); | |
app.emit('modelRemoted'); | |
}; | |
function overwriteMethodProperties(method) { | |
// Use the longer description for the 'notes' and just use the method name for the 'description' | |
method.originalDescription = method.originalDescription || method.description; | |
method.notes = method.originalDescription; | |
method.description = methodDescription(method); | |
return method; | |
} | |
function methodDescription(method) { | |
// Handle related methods by stripping out the __s | |
let name = method.name | |
.replace(/__(.+)__/, '$1 ') | |
.replace(/([A-Z])/g, ' $1') | |
.toLowerCase(); | |
return name | |
.slice(0, 1) | |
.toUpperCase() | |
.concat(name.slice(1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment