batmanjs/batman — pull request #1012 by jouh (2014-03-24 07:58:49+00:00)
Title: String support for the validate’s if and unless option.

This pull request changes so the validate’s if and unless option accepts a string, and it will look for an attribute or accessor with that name on the record.

**Example**
``` coffeescript
class App.Integration extends Batman.Model

@validate "paypal_email", email: true, if: "paypal_enabled"
```

**Discuss**
The possible to specify a string has been discussed in #883 but then it was suggested that string should be a reference to a function on the prototype. What you guys think about doing a @get(string) rather than call a function on the prototype? Is it a bad idea? In our app, we’re using a lot of conditional validations based directly on attributes so the @get(string) approach makes most since for us but maybe not so much for others.

Adding support for conditional validation based on a string makes it more in line with Rails but is syntactic sugar like this wanted in Batman? The only real benefit is that it makes the code shorter/cleaner. Is the extra code worth it? I can’t tell but love syntactic sugar. :)

Pull request includes tests and docs. A note about the docs though; English isn’t my primary language so please be on the lookout for grammatical errors and such. Thanks! :)