-
Notifications
You must be signed in to change notification settings - Fork 148
Description
Thanks so much for picking up the ball with this project! I was an early contributor.
When a relationship is defined, the serializer needs to determine which serializer to use. It uses both the optional serializer and polymorphic options to help guide it. It gets the job done in most cases, but there are definitely some hard rules that don't necessarily apply in all cases.
Consider the case of Single Table Inheritance. Say you have an Animal base class and 20 subclasses, Dog, Pig, Giraffe, etc. You may have different serialization rules for each, so they should each have their own serializer. Or maybe they all have the same serializer. Or maybe they have the same base class serializer, and only the ones that have something custom would need to define their own serializer. Maybe this can be done today using a polymorphic hash, but (a) you would have to list every possible class in the hash, and (b) it looks like there are some similar rules and limitations with how record_type is defined with polymorphic hashes.
I think an elegant solution would be to simply allow the serializer option to be specified as a Proc, like we do with attributes, conditionals, etc. It can include the same object and params arguments. This way, the author has total control over selecting the serializer based on the actual object that it is attempting to serialize.
What do you think of this approach? If it looks good, I will implement and create a PR.
Thanks again!