This gem is an extension on top of Representable which allows us to by default exclude properties/collections from representables and explicitly include them by setting right option on Representable.
Add following line to your Gemfile
You can make a collection
Expandable by includeing
Representable::Expandable in your
Representable and set
expandable: true for your expandable properties/colloections. Here is a sample:
module MessageRepresenter include Roar::JSON include Expandable property :id property :subject property :body, expandable: true collection :attachments, extend: AttachmentRepresenter, class: Attachment, expandable: true end
In the above example
attachments are expandable which means by default they won't get rendered in
MessageRepresenter. In order to explicitly add them to representer we need to set
expand options of representer using
message = Message.new(id: 'test', subject: 'test subject', body: 'test body', attachments: ['1', '2']) message.extend(MessageRepresenter).to_json(expand: ['attachments'])
expand gets an array as input.
Please create a Github issue once you find any issue or had any requests.
##Thanks Special thanks to @joeyAghion
Please see LICENSE for licensing details.