These are chat archives for dry-rb/chat

24th
Apr 2018
Tim Riley
@timriley
Apr 24 2018 00:26
@jonahx What you have in that code example above seems fine. There’s not any kind of first-class support for something like that.
Jonah
@jonahx
Apr 24 2018 00:27
@timriley thanks
Tim Riley
@timriley
Apr 24 2018 00:27
@jonahx Alternatively, you could just use the type definition directly whenever you need it?
Webservices = Types::Strict::Array(Types::Instance(Webservice))
services = Types::Webservices[some_array]
Jonah
@jonahx
Apr 24 2018 00:28
@timriley yeah, in this case i felt there was benefit in explictily naming the concept. Also, the real object has a from_string ctor so there’s a bit more reason to have it
Tim Riley
@timriley
Apr 24 2018 00:28
Right, that makes sense then.
Jonah
@jonahx
Apr 24 2018 00:30
any advice on the rspec question?
Tim Riley
@timriley
Apr 24 2018 00:32
Mind repeating it?
Jonah
@jonahx
Apr 24 2018 00:33
Also separate question for today: I have an Dry::Struct with an attribute with a Class type constraint. When using rspec, I want to pass in a double for the object. But an rspec double does not have type class. Have you ever run into this? What was your workaround?
Tim Riley
@timriley
Apr 24 2018 00:41
I’d just construct an object of the actual class :)
Jonah
@jonahx
Apr 24 2018 00:43
ha, you’re not as lazy as me. thanks :)
Tim Riley
@timriley
Apr 24 2018 00:51
Code should inform tests :)
(and if it makes testing too hard, well, that’s a code problem)
Jonah
@jonahx
Apr 24 2018 00:57
@timriley, well, the test is perfectly easy. it’s just that rspec double’s aren’t designed with type checking in mind, which is fair enough given how atypcal it is in ruby. imo dry::struct types bring a certain sanity to ruby that should be there, but the fact remains it’s still an addon to the language, so to speak.
Tim Riley
@timriley
Apr 24 2018 01:01
Yeah. I’d only use doubles where duck-typing matters more than the actual strict class check
Jonah
@jonahx
Apr 24 2018 01:05
@timriley which is indeed the case here. i sort of added the class constraint just as a way of enforcing the interface, but now that you mention it i think that’s where my mistake was — the contract really is just an interface and not a particular class. and removing the type constraint which i’ve what i did to fix the issue was probably the correct move anyway and not just a hack as i’ve been viewing it
Tim Riley
@timriley
Apr 24 2018 01:05
Cool :)
Alexander Chernik
@achernik
Apr 24 2018 15:19
Hello!
I have a question regarding dry-validation usage. Is it possible to "filter out" invalid parts instead of flat out rejecting entire hash?
I could use result.errors to filter result.output manually, but maybe there is another way?