Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'dry-validation'
class Schema < Dry::Validation::Schema
group :node do
key(:name) { |name| name.str? and name.filled? }
key(:children) do |children|
children.array? do
children.each { |child| child.group?(:node) }
end
end
end
end
schema = Schema.new
puts schema.call({
name: 'Right',
children: [
{name: 'Right Son' children: []},
{name: 'Right Daughter', children: []}
]
}).messages
# => []
schema.call({
name: 'Wrong',
children: [
{name: 1, children: nil},
]
}).messages
# => [... one of the children does not comply with the rules]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.