flatiron/resourceful — pull request #74 by yawnt (2012-06-03 09:31:37+00:00)
Title: Sync hooks

I wasn't really using callbacks in hooks for anything async and i noticed [issue #50](https://github.com/flatiron/resourceful/issues/50) , so here's a version of ```runAfterHooks``` and ```runBeforeHooks``` that supports synchronous functions...

it works pretty much the way @indexzero proposed.. if everything goes fine just ```return true```, anything else will be treated as an error and passed to ```finish()``` or ```callback()```

it uses the ```.length``` property of ```Function``` to find whether you expect a callback to be passed or not

example:

```javascript
var resourceful = require('./lib/resourceful');
resourceful.use('memory');

var Article = resourceful.define('Article', function() {
this.property('name');
});

Article.before('save', function(obj) {
obj.name = 'name';
return true;
});
Article.before('save', function(obj, next) {
obj.name = 'name2';
next();
});

Article.after('save', function(e, obj) {
obj.name = 'name3';
return true;
Article.after('save', function(e, obj, cbl) {
obj.name = 'name4';
cbl();
});
```