Help with dynamic representer

10 views
Skip to first unread message

Josh Cohen

unread,
Mar 9, 2015, 6:09:39 AM3/9/15
to roar...@googlegroups.com
Hi,

I'm trying to make a dynamic collection representer which will detect which representer to use for the items in the collection.
I created methods in the representer to examine the represented collection and construct the relevant constants for the representers as well as for the url helpers in the links collection.

However, these methods are out of scope for using as parameters in a collection method.
What's really got me twisted up is that it works for the class: parameter with collection, but not the extend: parameter.

How do I do this?
Please see this gist:
Look at the comment starting with HELP

Snippets
def xlass
represented.class.to_s.split(':')[0].constantize
end

def child_representer
base_class=represented.class.to_s.split(':')[0]
rep_class = 'Api::V1::' + base_class + 'Representer'
rep_class #.constantize
end
 
options = {
class: :xlass,
extend: QuestionRepresenter,
# HELP
# I want to call a method child_representer to dynamically find the right collection item representer
# this does not work and fails with no such method or error
#
embedded: true,
#decorator_scope: true,
as: "osdi:questions"
}
 
collection :all, options
 


--

Josh Cohen  jos...@gmail.com | @joshco | LinkedIn | GitHub  | OSDI opensupporter.org
"If [OSDI] succeeds, it could usher in the next chapter in political technology." - Washington Post

In the LGBT community, Domestic Abuse is the friendly-fire equivalent of bullying, sexual assault, discrimination, Religion based bigotry  and other types of  subjugation.

Let's stop it. Please help

Reply all
Reply to author
Forward
0 new messages