You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
book=Book.lastputsbook.name# lord of the ringsputsbook.author_name# j. r. r. tolkienputsbook.decorate.name# Lord of the Ringsputsbook.decorate.author_name# J. R. R. Tolkien
I'd love to be able to do something like this
classBook < Draper::Decoratordelegate_all# book.decorate.author_name will automatically use a decorated authordecorates_association:author
...
end
However, it does not work that way. A decorated book still sends name to an un-decorated author. So, I need to explicitly re-define the delegate method in the decorator in order to have book.decorate.author_name use a decorated author...
classBook < Draper::Decoratordelegate_alldecorates_association:author# code duplication... :(defauthor_nameauthor.nameend
...
end
If and when more delegate methods to author are defined on Book, this problem will only get nastier.
I haven't found a solution that does not involve duplicating code or violating the Law of Demeter.
Is there a cleaner way to implement this?
Thanks!
The text was updated successfully, but these errors were encountered:
(sorry in advance if I missed an issue or something in the docs)
Let's say I have two model classes,
Book
andAuthor
.Book
implements anauthor_name
method that delegatesname
to itsauthor
.My goal is to achieve something like this
I'd love to be able to do something like this
However, it does not work that way. A decorated
book
still sendsname
to an un-decoratedauthor
. So, I need to explicitly re-define the delegate method in the decorator in order to havebook.decorate.author_name
use a decoratedauthor
...If and when more delegate methods to
author
are defined onBook
, this problem will only get nastier.I haven't found a solution that does not involve duplicating code or violating the Law of Demeter.
Is there a cleaner way to implement this?
Thanks!
The text was updated successfully, but these errors were encountered: