Quantcast
Viewing all articles
Browse latest Browse all 3

Answer by Chico Carvalho for How to dynamically add properties to a ROAR representer?

I believe the best approach for the problem would be to use Roar's writer:. It completely turns control over the output to you by passing a handful of values it calls options to a provided lambda.

For example:

property :desired_property_name, writer: -> (represented:, doc:, **) do  doc[:desired_key] = represented.desired_valueend

There are a lot of uses not covered by the github readme but which are documented on the Trailblazer website. This one in particular can be found at http://trailblazer.to/gems/representable/3.0/function-api.html#writer.

Cheers!


Viewing all articles
Browse latest Browse all 3

Trending Articles