Next-gen ruby libs! » github.com/dry-rb » website: https://dry-rb.org » forum: https://discourse.dry-rb.org
format:
and some other custom type like “SocialSecurityNumber” or whatever also defined using format, how would I distinguish between the errors? (Assuming the error message is just keyed on the generic format?
key)
@solnic so i’ve been thinking about custom domain objects and how they relate to validations all day, and i don’t know how hard this would be for you to implement (or if it’s already implemented and i suck at reading docs!), but i think my concerns would be answered it there was a way to specify a “self validating object” in the schema. eg, say I already have an Email
object which will raise an error if I attempt to create an instance using a string which has no @
. Then I could write:
required(:email).filled(valid_instance?: Email)
And, assuming input was called with input
, the validation procedure would consist of running Email(input)
inside of a begin…rescue
block. If it ran without error, it would return the Email
instance. Otherwise the raised error message would be used as the validation error message. Thoughts?
Email
use that to get the error messages they need. so the second part of the above request is imo far less important than the first, and is only a convenience for small projects. the first part is pretty important imo, but i suspect there is a way to do it already somehow that i’m missing….
required(:email, Email)
will do what you need but Email
would have to encapsulate everything, so both coercion and rules
#to_ast
output more easily?