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
Decorate associations of a decorated object #8
Conversation
This allows decoration methods of an object to use decoration methods of an associated object.
WHen using metasearch, the obj being decorated doesn't have this method
+1 |
2 similar comments
+1 |
👍 |
Is somebody going to accept this pull request? I'm having to use ronen's repo (thanks ronen). |
+1 |
4 similar comments
👍 |
👍 |
👍 |
👍 |
@amatsuda Is there any specific reason not to merging this? If the only problem is merge conflict, I'll resolve and open another PR. |
@amatsuda could you please review this PR too ? |
After 5 years since the first proposal, this feature has been finally introduced since 0.9.0 gem! v0.8.0...v0.9.0 |
Hi, I just started using active_decorator, it seems great, thanks for making it!
But I quickly came across a feature that I needed: the ability to access an association's decorations. That is, considering the
Book
andAuthor
classes inspec/fake_app
-- I wanted to create a method inBookDecoration
like:which uses
AuthorDecoration#capitalized_name
. But typically althoughself
is decorated,se;f.author
is not decorated so the method fails.The solution I came up with is, after decorating an object, to introspect on all associations and override their methods in the object's singleton class, to call super() and return the decorated result. This approach seems to work, and has the feature of being "lazy" in that the associated objects only get decorated if/when they're accessed. I don't think it will conflict with anything else, though I'll admit I haven't put very deep thought into it.
Cheers