representation_wrap with a property value

38 views
Skip to first unread message

Nigel Soon

unread,
Jan 23, 2014, 12:50:08 AM1/23/14
to roar...@googlegroups.com
Hi,

I'm trying to wrap a hash with it's id. Using representation_wrap seem promising but I can only wrap it with a static string.

output e.g.

"1": {
  "id": 1,
  "name": "foo" 
},
"2": {
  "id": 2,
  "name": "bar"
}

representer e.g.

module QuestionRepresenter
  include Roar::Representer::JSON

  self.representation_wrap = @id

  property :id
  property :name
end


Any ideas?

Cheers,

Nigel

Nick Sutterer

unread,
Jan 23, 2014, 4:16:02 PM1/23/14
to roar...@googlegroups.com
Hey Nigel,

this is actually something I wanted to implement for a while: allowing lambdas for names (properties and wrap). I'll open a ticket to myself ;)

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.

Nigel Soon

unread,
Jan 23, 2014, 5:03:49 PM1/23/14
to roar...@googlegroups.com
Awesome thanks Nick. Let me know how you go.

Nick Sutterer

unread,
Jan 23, 2014, 7:07:04 PM1/23/14
to roar...@googlegroups.com
Nigel, do you need a work-around? You could manually set the wrap on each instance accessing .representable_attrs.wrap= (check this: https://github.com/apotonick/representable/blob/master/lib/representable/config.rb#L34)

Nigel Soon

unread,
Jan 23, 2014, 10:10:17 PM1/23/14
to roar...@googlegroups.com
Ah that's cool. I will go with your suggestion.

Cheers,

Nigel

Nick Sutterer

unread,
Apr 8, 2014, 11:06:26 PM4/8/14
to roar...@googlegroups.com
Hi Nigel,

the `representation_wrap` option is now dynamic in 1.8. Have fun with https://github.com/apotonick/representable#available-options

Nick
Reply all
Reply to author
Forward
0 new messages