I have Hanami 1.3.3 and two validators there: for create and update actions like these
module Validators
module MyEntities
class Create
include Hanami::Validations::Form
include Validatable
messages :i18n
validations do
required(:first_attr).filled(:bool?)
required(:second_attr).filled(:int?)
required(:attr_for_create).filled(:str?)
end
end
end
end
module Validators
module MyEntities
class Update
include Hanami::Validations::Form
include Validatable
messages :i18n
validations do
required(:first_attr).filled(:bool?)
required(:second_attr).filled(:int?)
required(:attr_for_update).filled(:str?)
end
end
end
end
In fact, the number of validation rules is more than twenty
As you see there is a lot of repetitive code here
I want to DRY it and use some inheritance
I couldn't find some receipts for this. Just discussion in GitHub issue. Outcome of that discussion: it's very tricky
How to use inherited validators in Hanami?