Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Utils module #322

Merged
merged 5 commits into from Oct 30, 2012
Merged

Remove Utils module #322

merged 5 commits into from Oct 30, 2012

Conversation

haines
Copy link
Contributor

@haines haines commented Oct 30, 2012

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:

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

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

What do you reckon?

Use `alias` instead of `alias_method` for consistency, and move all
the different aliases for `model` together
steveklabnik added a commit that referenced this pull request Oct 30, 2012
@steveklabnik steveklabnik merged commit f1c7226 into drapergem:master Oct 30, 2012
@steveklabnik
Copy link
Member

I reckon this is awesome. Thank you. The matcher thing especially is sweeeet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants