flash-gordon on deprecate-class-name-inferring
Deprecate predicate inferring f… (compare)
flash-gordon on or_nil-extension
Add Type#or_nil via builders ex… (compare)
flash-gordon on or_nil-extension
Add Type#or_nil via builders ex… (compare)
dry-bot on master
[devtools] sync (compare)
flash-gordon on master
Update CHANGELOG (compare)
flash-gordon on params-string
flash-gordon on master
Add params.string (closes #403)… Merge pull request #412 from dr… (compare)
flash-gordon on params-string
Add params.string (closes #403)… (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"]}>
>> @schema.call(user_id: nil)
=> #<Dry::Validation::Result output={:user_id=>nil} messages={}>