Skip to content

Instantly share code, notes, and snippets.

@zbarbuto
Last active December 15, 2017 05:02
Show Gist options
  • Save zbarbuto/b2feb5ec35578f5cfeeb905e13845317 to your computer and use it in GitHub Desktop.
Save zbarbuto/b2feb5ec35578f5cfeeb905e13845317 to your computer and use it in GitHub Desktop.
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