jgaskins/perpetuity — Issue #3: ActiveModel wrapper
Author: jgaskins
Created: 2012-02-26 06:55:07+00:00
State: open

## What do we need ActiveModel for?

Rails counts on a lot of ActiveModel methods in order to do things like `form_for` in views and `redirect_to @foo` in controllers.

## How should it be done?

As always, several possibilities floating around in my head.

### Using mappers as ActiveModel wrappers

Consider [this gist](https://gist.github.com/1914273). Unfortunately, this means that we need to make the mapper respond to all of the attributes (for `form_for`) and the id field (for `redirect_to`). This is trivial to do, but feels weird.

### Include wrapper functionality into domain objects

Another possibility is to include the ActiveModel wrapper into the domain class (essentially just moving the `include Perpetuity::ActiveModelWrapper` call in the aforementioned gist). This would make the ActiveModel functionality expected inside those objects, but it means that the objects themselves aren't entirely decoupled from Rails. The primary idea behind Perpetuity is that there are no other dependencies other than those required for the domain objects to do their job.

### Create an entirely different class specifically for wrapping domain objects to use ActiveModel

This idea maintains the purity of the domain objects, keeps the domain-object calls outside of the mappers and still allows us to use ActiveModel functionality. This seems like it might be the best solution, but I'm not 100% sold on it yet. Here's [an example](https://gist.github.com/1914489). If we could come up with a smoother way of calling it, it might be better.