Sha256: 6755e30056f8e496bd7bb28249ea76f4e3011f6f4415861b5f2764486d191c96

Contents?: true

Size: 557 Bytes

Versions: 12

Compression:

Stored size: 557 Bytes

Contents

require 'dry-validation'

schema = Dry::Validation.Schema do
  configure do
    def self.messages
      super.merge(en: {
        errors: {
          john_email?: '%{value} is not a john email',
          example_email?: '%{value} is not a example email'
        } })
    end
  end

  required(:email).filled

  validate(example_email?: :email) do |value|
    value.end_with?('@example.com')
  end

  validate(john_email?: :email) do |value|
    value.start_with?('john')
  end
end

errors = schema.call(email: 'jane@doe.org').messages

puts errors.inspect

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dry-validation-0.13.3 examples/multiple.rb
dry-validation-0.13.2 examples/multiple.rb
dry-validation-0.13.1 examples/multiple.rb
dry-validation-0.11.2 examples/multiple.rb
dry-validation-0.12.3 examples/multiple.rb
dry-validation-0.13.0 examples/multiple.rb
dry-validation-0.12.2 examples/multiple.rb
dry-validation-0.12.1 examples/multiple.rb
dry-validation-0.12.0 examples/multiple.rb
dry-validation-0.11.1 examples/multiple.rb
dry-validation-0.11.0 examples/multiple.rb
dry-validation-0.10.7 examples/multiple.rb