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 .decorates method and all class method proxying #311
Conversation
|
Well..... So there's a big schism here. One is 'pretend to be like AR as much as possible.' The other is 'follow good OO design.' ;) What I'd like for 2.0 (yes, I know we're not at 1.0 yet ;) ) is to build a core of 'good oo' stuff and then add a layer of 'ar compatible stuff' on top. So that people can do both. |
|
Hmmm yes fair enough. How about something like class ProductDecorator < Draper::Decorator
# inferred model
add_finders
# explicit model
add_finders for: :widget
endThen the AR stuff could be moved into a module that was extended on demand? Then it would be possible to write some decorators that could deal with multiple classes, and some that were tightly bound to one. Edit In fact, going back to composition over inheritance, I could imagine |
|
Hmmmmm. I kinda like that, actually. Sounds pretty reasonable. |
|
Awesome! I'll have a crack at this tomorrow (I'm on UK time). |
|
See what you think, I ended up not creating a new object on the basis that the methods we are dynamically adding are already simple delegates to another object. |
|
This looks great. I only want to have one more bikeshed: I'm not sure that I'm not sure what it should be, though. |
|
Just spitballing here... class ProductDecorator < Draper::Decorator
can_find :product
finds :product
finds_model :product
findable :product
endNot sure I love any of them. |
|
Just gonna toss something at the wall cause I walked in here from twitter and class MyFancyUserDecorator < UserDecorator
scope User.fancy
end |
|
Hmmmmmmmmmm |
|
|
|
@steveklabnik No worries, I didn't like it much either but couldn't come up with anything better. And we're going to have to live with our bikesheds once this goes 1.0 - let's paint them properly :) @stevenharman My favourite of those is Let me put another one up for consideration too: @lest At the moment they are right there in the |
|
Hey @steveklabnik, I went with When I went to rebase, the specs were a bit of a nightmare, as there were a lot of methods on |
Remove .decorates method and all class method proxying
|
Looks good, thanks. I'd rather have the feature than continue the bikeshed. :) And that name is 'good enough'! |
I thought I'd throw this out there and see what people thought.
@steveklabnik has mentioned a few times about removing
.decorates, and letting one decorator decorate multiple models. I like the idea of decoupling the decorator from the model class as much as possible.An important consequence of this is that it would no longer be possible to proxy class methods, in particular
ProductDecorator.all,ProductDecorator.findand friends.Personally I think this is a good thing, I've never been very comfortable with that syntax and have preferred
ProductDecorator.decorate(Product.all)because, conceptually, the idea of "finding a ProductDecorator" doesn't sit well with me compared to "finding a Product and decorating it".Thoughts?