require 'dry-validation'
UserSchema = Dry::Validation.Schema do
configure do
def unique?(org_id, email)
puts "email unique?: #{email} within #{org_id}"
true
end
end
required(:email).filled
required(:org_id).filled(:int?)
rule(unique_email: [:email, :org_id]) do |email, org_id|
email.unique?(org_id)
end
end
I’m planning to unify this syntax with normal rules, unfortunately it’s still using the older DSL where predicates in the DSL are called on “values” like email.unique?(org_id), in 1.0.0 it’s gonna be unique?(email, org_id). I figured I should mention that