dry-bot on master
[devtools] sync (compare)
flash-gordon on master
It's 2021 everyone! (compare)
flash-gordon on v1.5.0
dry-bot on master
[devtools] sync (compare)
flash-gordon on master
Set release date (compare)
flash-gordon on master
Add docs for fallbacks and cust… (compare)
dry-bot on master
[devtools] sync (compare)
flash-gordon on master
Update changelog.yml (compare)
gem 'dry-validation', '~> 0.10'
require 'dry/validation'
schema =
Dry::Validation.Schema do
required(:foo) { str? }
required(:bar) { str? | int? }
end
schema.call(foo: 1, bar: 'blah').message_set.first.text # => "must be a string"
begin
schema.call(foo: 'hi', bar: 1.0).message_set.first.text
rescue => err
p err
end
# >> #<NoMethodError: undefined method `text' for #<Dry::Validation::Message::Or:0x007fbcb32514b8>>
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"]}>