drapergem/draper — pull request #480 by urbanautomaton (2013-02-19 21:14:58+00:00)
Title: Add option to specify namespace for decorator lookup

Hi,

In our app, we use decorators in a number of different contexts - e.g. constructing an API response, rendering HTML templates, and so forth. We keep separate decorators for each context, and namespace them to keep them organised, so our `Activity` model has a root-level decorator, but also `API::ActivityDecorator` and `HTML::ActivityDecorator`.

This patch adds a `:namespace` option to the various decoration methods, so that users can do things like this:

```
> Activity.last.decorate
=> #>
> Activity.last.decorate(:namespace => HTML)
=> #>
```

The option can also be passed to `Decorator.decorate_collection`, `.decorates_association` and the like:

```ruby
module API
class ActivityDecorator < Draper::Decorator
decorates_association :comments, :namespace => API
end
end
```
```
> Activity.last.decorate(:namespace => API).comments.first
=> #>
```

Is this a feature you'd be interested in including? The ability to organise our decorators in this manner has certainly helped us a lot, and we think others might find it useful too...

Cheers,
Simon