representable
representable copied to clipboard
Default options
It would be awesome if we could have a clean way to specify default options for all properties in a single line.
Example:
module BandRepresenter
include Roar::Representer::JSON
include Roar::Representer::Feature::Hypermedia
# This is how I do it right now
def self.property(name, options={})
super(name, options.merge!(render_nil: true))
end
# This is how I would like to do it.
default_options render_nil: true
property :id
property :whatever1
property :whatever2
property :whatever3
property :whatever4
property :whatever5
end
Thanks
+1
+1, would love this feature. We are having a fun issue:
- using property to create a json hash
- reading back the json hash from a search engine (elasticsearch)
- using a DelegateClass to wrap that hash..it throws errors because some methods are not defined because they got represented as nil and therefore didn't make it into the representation at all
Here's the solution we used to monkeypatch Roar to define this globally https://gist.github.com/skwp/5afe7b2a238260f301ac
Ok, I can see how this is helpful. The defaults
will be copied to inline representers, right?
It would be even greater (I would say it is a must) to be able to configure defaults in a global way (for all representers). I'm thinking in render_nil
option, which usually is an overall API decision, so it would be also tiring to have to declare it in each representer.
@waiting-for-dev Hi, did the global defaults feature get implemented?