balderdashy/waterline — pull request #161 by ragulka (2013-10-30 08:46:00+00:00)
Title: Allow providing rule value as a function and add support for anchor custom type context.

There are 2 distinct commits in this PR that are related but do pretty different things.

**The first one lets you specify rule values as functions that have the currently set values as `this` context.** What does that mean? Here's a simple example:

```javascript
attributes: {
startDate: {
type: 'date',
before: function() {
return this.endDate;
}
},
endDate: {
type: 'date',
after: function() {
return this.startDate;
}
}
}
```

It also supports async functions:

```javascript
attributes: {
website: {
type: 'string',
contains: function(cb) {
setTimeout(function() {
cb('http://');
}, 1);
}
}
}
```

Note: the above is completely independent from anchor.
Note: the 3rd commit simply refactors my initial test to make more sense.

**The second commit provides the model's currently set values as the `this` context to anchor**. See https://github.com/balderdashy/anchor/pull/24 for more details.

Please note: the second commit requires the aforementioned feature in anchor to be merged in, otherwise the tests will fail, even though it does not break any of the existing functionality.