These are chat archives for dry-rb/chat

12th
May 2018
Jonah
@jonahx
May 12 2018 00:52
how can i build a custom type to verify not that an object is an instance of certain class, but that it conforms to a specific interface, ie, has methods :a, :b, and :c defined on it, eg?
Jonah
@jonahx
May 12 2018 01:23

separate question: is it possible to specify a custom error message when a constraint is violated. eg, consider:

  URI = Types::Strict::String.constrained(format: URI::regexp)

when this is violated, the message includes the very long URI regexp. it would be nice if I could specify the message as “The string does not match URI::regexp”

Nikita Shilnikov
@flash-gordon
May 12 2018 14:14
there's no way to enforce presence of methods with dry-types, I'm also not sure this makes sense in general
in a way, dry-types targets data, not objects
and for producing nice messages there's dry-validation
Jonah
@jonahx
May 12 2018 15:33

@flash-gordon thanks.

in a way, dry-types targets data, not objects

would it be fair to say that in “the dry rb way,” object dependencies would be handled with the auto-injector, and data dependencies would be handles with dry-struct / dry-types?

and for producing nice messages there's dry-validation

yeah, my question was specifically about the type error messages. it’s a small point, not really important.