featurehelp wanted
Repository metrics
- Stars
- (1,421 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Examples
require 'dry-validation'
class PropsContract < Dry::Validation::Contract
json do
required(:contacts).value(:array, min_size?: 1).each do
hash do
required(:name).filled(:string)
required(:email).filled(:string)
required(:phone).filled(:string)
end
end
end
rule("contacts[].email").each do
key.failure("email not valid") unless value.include?('@')
end
end
c = PropsContract.new
c.(
contacts: [
{ name: 'Jane', email: 'jane@doe.org', phone: '123' },
{ name: 'John', email: 'oops', phone: '123' }
]).errors.to_h.inspect
# {:email=>{1=>["email not valid"]}}
Resources
Refs #603