Currently the gem supports conditional attributes and relationships by passing an if option. I think it would make sense to make it symmetric by also providing an unless option, which would do the opposite.
This would be in line with how many other gems handle conditionals, including AMS and Rails in many places (callbacks, validations, etc.) and well, even the Ruby language itself with the unless keyword.
This feature would turn this:
class MovieSerializer
include FastJsonapi::ObjectSerializer
attribute :title, if: ->(movie) { !movie.secret_title? }
has_many :actors, if: ->(movie) { !movie.in_development? }
end
Into the much nicer and easier to read version:
class MovieSerializer
include FastJsonapi::ObjectSerializer
attribute :title, unless: &:secret_title?
has_many :actors, unless: &:in_development?
end
I'd be happy to submit a PR for this if you guys agree that it's a worthwhile feature.
Currently the gem supports conditional attributes and relationships by passing an
ifoption. I think it would make sense to make it symmetric by also providing anunlessoption, which would do the opposite.This would be in line with how many other gems handle conditionals, including AMS and Rails in many places (callbacks, validations, etc.) and well, even the Ruby language itself with the
unlesskeyword.This feature would turn this:
Into the much nicer and easier to read version:
I'd be happy to submit a PR for this if you guys agree that it's a worthwhile feature.