Adding one more field into Representer

20 views
Skip to first unread message

Alberto Leal

unread,
May 14, 2013, 9:41:59 AM5/14/13
to roar...@googlegroups.com
Hi guys!

I'm using representable to create a representer for my collection of apis. I would like to add one more field which isn't mapped in my model (item_count - representing the total items in my collection). Is there any automatic way to achieve that with the gem? Otherwise, how can I do that manually?

thanks a lot!
Alberto

Alberto Leal

unread,
May 14, 2013, 9:51:37 AM5/14/13
to roar...@googlegroups.com
Hi all!

Just tried with a simple scenario and adding a new property and setting that works:

property :age
def age; 8; end;

I think the problem is with the object returned by usergrid_iron gem. Going to investigate it deeply.

thanks!

Nick Sutterer

unread,
May 14, 2013, 8:55:36 PM5/14/13
to roar...@googlegroups.com
Hi Alberto,

when using the module representer (not the decorator) you can simply add methods and then define properties on that, as you already did. You can also use :getter and :setter if you prefer a lambda:

property :age, getter: lambda { |*| @age_from_usergrid }

The lambdas are executed in the represented model's context. Check here for more docs: https://github.com/apotonick/representable/#passing-options (also the next paragraph "Using Helpers"). Anything else you're having trouble with?

Nick


--
You received this message because you are subscribed to the Google Groups "Roar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roar-talk+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages