Possible to access @options in a Serializer as it was in 0.8.
By doing so, you can use the options to filter attributes:
keys.delete(:foo) if @options[:bar]
I would like to see this as well. My use case:
I'm using CarrierWave and need to return image urls in my API. I'd like to have 1 serializer that renders an array of image urls. I was thinking of creating a declarative API for it like:
attribute :cover_image, serializer: ImageVersionSerializer, versions: [:thumb, :large]
But I can't specify versions without access to the options.
I have a similar use case where a serializer should render an array of things (time series elements) and i need to pass a time range parameter to the serializer.
I could not find a good solution for this without subclassing ActiveModel::Serializer and ActiveModel::ArraySerializer.
Having access to options would be really helpful. (+1)
Having a dedicated :context option for user defined options could be another option.
This way we would make sure that "reserved" options like meta, meta_key, root and scope don't cause conflicts.
@ahx I really like this approach. Done
Cool. Oat (https://github.com/ismasan/oat) is using this approach as well btw.
I like this. Can I get a rebase, please?
Custom options are accessible in serializer (via :context)
Thanks! Let's see what Travis says...
Travis says yes! thank you!