Nico-Taing/yaml_record — Issue #3: Add validations
Author: nesquena
Created: 2012-02-01 08:38:58+00:00
State: open

Add validation support to yaml_record. Simplest will be to be able to define `valid?` and then have it run on `update_attributes` and `save`:

```
class Post < YamlRecord::Base
def valid?
errors add :title, "cannot be blank" if title.blank?
errors.add :description, "cannot be blank" if self.description.blank?
end
end
```

and then:

```
p = Post.new.save => false
p.errors # => { :title => ["cannot be blank"], :description => ["cannot be blank"] }
```

We can also add helpers as well:

```
class Post < YamlRecord::Base
validates_presence_of :title
validates_presence_of :description
end
```

which will automatically set:

```
p = Post.new.save => false
p.errors # => { :title => ["cannot be blank"], :description => ["cannot be blank"] }
```