Created
February 16, 2018 17:33
-
-
Save bind-disney/5a10b8803c79995e91f32797d440cddf 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 | |
required(:field_1).filled(:str?) | |
required(:field_2).filled(:int?) | |
rule(field_2_depends_on_field_1: [:field_1, :field_2]) do |field_1, field_2| | |
field_1.eql?('Foo').then(field_2.eql?(0)) & field_1.eql?('Bar').then(field_2.eql?(1)) | |
end | |
end | |
puts schema.call(field_1: 'Foo', field_2: 0).success? | |
puts schema.call(field_1: 'Bar', field_2: 0).success? | |
puts schema.call(field_1: 'Foo', field_2: 1).success? | |
puts schema.call(field_1: 'Bar', field_2: 1).success? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment