I’m attempting to move away from reform to dry-validation. One reform feature we were making use of was the ability to reuse our existing ActiveModel validations:
class Jobs::UpdateForm < Reform::Form extend ActiveModel::ModelValidations # various properties copy_validations_from Project end
This made it convenient to move validation from our models towards the edges of our application, but we also kept the validations on the models as a “last line of defense” and because not all paths went through the new validations.
I don’t see an obvious way to do the same with dry-validations.
My best idea so far is to define a base contract for a given model and have a bunch of rules as macros. Then the “pure model” contract would use all of those macros and I’d somehow shuttle the errors back to ActiveModel. For forms / JSON endpoints, I’d define the properties that are allowed on that endpoint and then use the appropriate macros.
I don’t see a way around duplicating the dry-logic bits (e.g.
.value(:integer, gt?: -365, lt?: 365)).
Are there any great patterns that exist that I could crib from to get started?