I have been digging trying to find a way to define my own types (custom coercion and validity checks and constraints). For example I want a type that checks that a given value
is_a? MyClass. I found a way to do coercions from the base types here https://discuss.dry-rb.org/t/coercing-to-domain-model/69/2 but I do not know how to express custom constraints or build something that isn’t based on existing types.
To put it more concrete, how do I create a type that ensures that the given value is an Either (an instance of either Right or Left)? That way I can create for instance a struct and define something like
attribute :result, Types::Either.
I tried my best looking in the code to find a way but the types repo is quite complex and I couldn’t figure it out on my own so any help is appreciated. Thanks!