-
-
Save dsisnero/fa2cf9af6b35a3bd67501f733c2c97b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dry-validation' | |
schema = Dry::Validation.Schema do | |
configure do | |
def self.messages | |
super.merge(en: { errors: { foo: 'either a or b can be filled' } }) | |
end | |
end | |
required(:a).maybe | |
required(:b).maybe | |
rule(foo: %i[a b]) do |a, b| | |
a.filled? ^ b.filled? | |
end | |
end | |
puts schema.(a: 'huh', b: 'heh').errors.inspect | |
# {:foo=>["either a or b can be filled"]} | |
puts schema.(a: 'huh', b: nil).errors.inspect | |
# {} | |
puts schema.(a: nil, b: 'heh').errors.inspect | |
# {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment