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

Decorate associations of a decorated object #8

Closed
wants to merge 2 commits into from

Conversation

ronen
Copy link

@ronen ronen commented May 29, 2012

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 and Author classes in spec/fake_app -- I wanted to create a method in BookDecoration like:

def attribution
     "#{title}, by #{author.capitalized_name}"
end

which uses AuthorDecoration#capitalized_name. But typically although self 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

ronen added 2 commits May 29, 2012 15:01
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
@auxout
Copy link

auxout commented Sep 29, 2012

+1

2 similar comments
@kinopyo
Copy link

kinopyo commented Nov 27, 2012

+1

@soycamo
Copy link

soycamo commented Dec 20, 2012

👍

@damien-roche
Copy link

Is somebody going to accept this pull request? I'm having to use ronen's repo (thanks ronen).

@icortex
Copy link
Contributor

icortex commented Nov 22, 2013

+1

4 similar comments
@y-yagi
Copy link
Contributor

y-yagi commented Jan 15, 2014

👍

@koko1000ban
Copy link

👍

@kenchan
Copy link

kenchan commented May 16, 2014

👍

@ken1flan
Copy link

👍

@mshibuya
Copy link
Contributor

mshibuya commented Nov 5, 2014

@amatsuda Is there any specific reason not to merging this?
I don't believe ActiveDecorator should be lacking in such a fundamental feature.

If the only problem is merge conflict, I'll resolve and open another PR.

@vala
Copy link
Contributor

vala commented Mar 30, 2015

@amatsuda could you please review this PR too ?

@amatsuda
Copy link
Owner

amatsuda commented Apr 5, 2017

After 5 years since the first proposal, this feature has been finally introduced since 0.9.0 gem! v0.8.0...v0.9.0
I'm so sorry that I couldn't make this happen earlier, but I hope you all enjoy this new feature!

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