As of right now it looks like, when creating a validator, I have the option of either using my custom global predicates OR defining inline predicates. Looking through the validation code there is indeed an either restriction.
The trouble is this, there are predicates that totally make sense in the global space such as email?
whereas more specific ones that check, for instance, on the uniqueness of a value. (And yes, I know validators don’t guarantee uniqueness but they work just fine for error reporting and if a race condition occurs the database will throw its own error.) So, questions:
-
When doing complex validation that is context specific (e.g. is this email already in use with the related resource type or does the user have enough cash in his virtual wallet for the transaction amount?) is Hanami validation even the right tool or should it be used purely for data validation and coercion with some other process in place for dealing with context specific validation and error messages? (If this is the case, globals only seem to make more sense.)
-
If it is the right tool, what is the solution for combining context specific validations (is this email available in this instance) with global ones (is this email address formatted properly) in a single validator (scheme)?
-
If it isn’t, what is the best practice for dealing with these kinds of errors and error reporting? Is this expected to happen inside of an interacror and is there a generic error reporting interface from there that matches up with the more basic validation errors?
There is a lot I can figure out from code dives, but I’m trying hard to understand intent and best practices as well. I’d be happy to document these topics once I grok them myself, but at the moment I feel like I’d just be the blind leading the blind.