Skip to content

Instantly share code, notes, and snippets.

@prestonp
Last active August 29, 2015 14:03
Show Gist options
  • Save prestonp/c494723bdc79f94072c2 to your computer and use it in GitHub Desktop.
Save prestonp/c494723bdc79f94072c2 to your computer and use it in GitHub Desktop.
dirac plugins
// monkey patches dirac with ./plugins folder
var dirac = require('dirac');
modules.exports = function(options) {
options = options || {};
// plugins folder contains table folders, each containing plugin definitions
fs.readDir(options.path || './plugins');
// pseudocode
foreach table
foreach plugin
dirac.dals[table][plugin.type](plugin.method, plugin.handler);
};
// ./plugins/orders/statuses.js
module.exports = [
{ type: 'before'
, method: 'find'
, handler: function submittedDate( $query, schema, next) { }
},
{ type: 'before'
, method: 'findOne'
, handler: function statusDateSort( $query, schema, next) { }
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment