Created
April 11, 2018 10:41
-
-
Save k-hamada/89f890e7b90d03b47e8a8a1feed3f7d6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'bundler/inline' | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'dry-validation' | |
end | |
schema = Dry::Validation.Schema do | |
optional(:y).filled(:int?) | |
optional(:z).filled(:odd?) | |
optional(:x).filled(:int?) | |
.when(eql?: 1) { | |
required(:y).filled(:odd?) | |
} | |
end | |
p schema.({}) | |
p schema.({x: 1}) | |
p schema.({x: 2}) | |
p schema.({x: 1, y: 1}) | |
p schema.({x: 2, y: 1}) | |
p schema.({x: 1, y: 2}) | |
p schema.({x: 2, y: 2}) | |
p schema.({z: 1}) | |
p schema.({z: 2}) |
Author
k-hamada
commented
Apr 11, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment