drapergem/draper — pull request #322 by haines (2012-10-30 23:03:33+00:00)
Title: Remove Utils module

I think that the chain of decorators applied to a model should be a method on `Decorator` not a procedural function in the `Utils` namespace.

I have called it `applied_decorators`, and added `decorated_with?` to test if a given decorator is in the chain. This means we get the RSpec matcher for free:

```ruby
something.should be_decorated_with SomethingDecorator
```

A common interface between `Decorator` and `Decoratable` is useful so that we can apply this test to undecorated models, so I added these methods to `Decoratable` too (returning `[]` and `false` respectively, as you might expect).

While I was at it I added a `decorated?` method that returns false on models and true on decorators. Potentially useful for people who are inadvertently double-decorating.

And following that thought process I prevented `Decorator` from proxying `#decorate` to the model, which means that we can safely do `decorator = possibly_decorated_object.decorate`. Previously, we had

```ruby
product = SpecificProductDecorator.new(Product.new)
decorator = product.decorate
# decorator is now a ProductDecorator
# the SpecificProductDecorator is lost
```

What do you reckon?