apotonick/reform — pull request #109 by cameron-martin (2014-07-14 02:59:24+00:00)
Title: FEATURE: Added ability to copy validations from the underlying model.

The works like so:

```ruby

class Album
include ActiveModel::Model
attr_accessor :title, :artist

validates :title, :artist, presence: true
end

class AlbumForm < Reform::Form
extend ActiveModel::ModelValidations

property :title
property :artist_name, as: :artist

copy_validations_from Album
end
```

And for composite forms:

```ruby
class AlbumRating
include ActiveModel::Model

attr_accessor :rating

validates :rating, numericality: { greater_than_or_equal_to: 0 }

end

class CompositeForm < Reform::Form
include Composition
extend ActiveModel::ModelValidations

model :album

property :title, on: :album
property :artist_name, as: :artist, on: :album
property :rating, on: :album_rating

copy_validations_from album: Album, album_rating: AlbumRating

end
```

I don't think it works for uniqeness validations, because I think reform only intercepts `validates_uniqueness_of`, not the `validates :uniqueness` syntax, which this uses. I will add tests for & fix this.

I also think that `representable_class.representable_attrs` would benefit from being an instance of a Mapping class rather than just a hash, so that forward and reverse mappings could be done with just one method call.