Closed zubin closed 6 months ago
Closing because I found a way to do it:
extend JSONAPI::Serializable::Resource::ConditionalFields
link :boom, if: -> { @object.can_go_boom? } do
href "the-boom-url"
end
Couldn't see it in the docs, came across it here: https://github.com/jsonapi-rb/jsonapi-serializable/issues/49
My use case is to only include possible actions on a resource.
I want to omit ones which aren't relevant, depending on the resource state.
Something like this:
Currently this results in
links: {boom: nil}
but I'd prefer any links which are nil to be removed (likeHash#compact
).Does this make sense? I'd be happy to make a PR if the idea is sound.