Sha256: 7d2ace4e6b9b682c67778978207e1484bf08a537bf87a94617c5fb0d3fa5f237

Contents?: true

Size: 560 Bytes

Versions: 6

Compression:

Stored size: 560 Bytes

Contents

require 'dry-validation'

class Schema < Dry::Validation::Schema
  key(:address) do |address|
    address.hash? do
      address.key(:city) do |city|
        city.min_size?(3)
      end

      address.key(:street) do |street|
        street.filled?
      end

      address.key(:country) do |country|
        country.key(:name, &:filled?)
        country.key(:code, &:filled?)
      end
    end
  end
end

schema = Schema.new

errors = schema.call({}).messages

puts errors.inspect

errors = schema.call(address: { city: 'NYC' }).messages

puts errors.inspect

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dry-validation-0.6.0 examples/nested.rb
dry-validation-0.5.0 examples/nested.rb
dry-validation-0.4.1 examples/nested.rb
dry-validation-0.4.0 examples/nested.rb
dry-validation-0.3.1 examples/nested.rb
dry-validation-0.3.0 examples/nested.rb