NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

Conditional shortcut for required validation #157

Closed ajselvig closed 9 years ago

ajselvig commented 9 years ago

This isn't a bug, really, but it would be nice to be able to specify an inline conditional for the required validation. Essentially, to be able to replace:

belongs_to :bar
validates :bar, presence: true, if: -> {self.some_method}

with

belongs_to :bar, required: -> {self.some_method}

It's a minor difference, just thought I'd bring it up.

nviennot commented 9 years ago

You can. If you pass options, they are passed to the validator:

belongs_to :bar, required: ->  {if: :some_method}

:D

ajselvig commented 9 years ago

Gotcha, thanks. Maybe worth noting in the docs?