dry-bot on master
[devtools] config sync (compare)
dry-bot on master
[devtools] config sync (compare)
dry-bot on master
[devtools] config sync (compare)
dry-bot on master
[devtools] config sync (compare)
gem 'dry-validation', '~> 0.10'
require 'dry/validation'
SCHEMA =
Dry::Validation.Schema do
required(:foo) { str? }
required(:bar, %i[string int]) { str? | int? }
end
SCHEMA.call(foo: 1, bar: 'blah').message_set.first.to_s # => "must be a string"
begin
SCHEMA.call(foo: 'hi', bar: 1.0).message_set.first.to_s # => "must be a string or must be an integer"
rescue => err
p err
end
Result#errors
and Result#hints
/home/monkey/.gem/ruby/2.2.5/gems/dry-types-0.9.0/lib/dry/types/compiler.rb:80:in `merge': no implicit conversion of Dry::Types::Safe into Hash (TypeError)
from /home/monkey/.gem/ruby/2.2.5/gems/dry-types-0.9.0/lib/dry/types/compiler.rb:80:in `each'
case
for simple ugh ... cases
messages
that merge both errors and hints, this turned out to be problematic in some cases so it was separated in 0.10.0
So I tried
required(:user_id).maybe(:int?)
required(:global_auth_id).maybe(:str?)
rule(valid_user: [:user_id, :global_auth_id]) do |user_id, global_auth_id|
user_id.false?.then(global_auth_id.filled?)
end
rule(valid_auth_id: [:user_id, :global_auth_id]) do |user_id, global_auth_id|
global_auth_id.false?.then(user_id.filled?)
end
but i get
>> @schema.call(global_auth_id: '2')
=> #<Dry::Validation::Result output={:global_auth_id=>"2"} messages={:user_id=>["is missing"]}>
>> @schema.call(user_id: nil)
=> #<Dry::Validation::Result output={:user_id=>nil} messages={}>