These are chat archives for dry-rb/chat

23rd
Oct 2016
Nick Sutterer
@apotonick
Oct 23 2016 04:00
hey guys, how can i find out if something is defined in a Container, even when the value is false or nil? e.g. container[:a] will return nil and i don't know if that's the value or wasn't found. something like has_key? ?
hm, key? seems to be the method
why not has_key?? can we add that? i want to treat dry-containers exactly the way i treat read-only hashes
i take everything back, i didn't know key? is an official hash API method. nick: shut up. :blush:
Nick Sutterer
@apotonick
Oct 23 2016 04:10
i have great news, BTW, dry-container is now seamlessly integrated in Trailblazer::Operation, and the new 1.2 "pipetree semantics" make it even more functional, it will be interesting to see how people will mix the "two worlds" soon
Tim Riley
@timriley
Oct 23 2016 07:29
@apotonick that sounds exciting! Do you have any code that exemplifies how they fit together?
Nick Sutterer
@apotonick
Oct 23 2016 07:34
@timriley it's more than exciting, it's f*cking awesome, really, it fits together so well
i will blog about it once 1.2 is ready, i will highlight the DRY.rb integration so you guys get as much expose as possible!
i still have to write my own strategy for auto_inject, though
@timriley could show you some test code, but i think it's better to present you a blog post
Tim Riley
@timriley
Oct 23 2016 07:41
heh, ok :)
BTW, there’s a PR open for auto_inject that might come close to what you need
dry-rb/dry-auto_inject#32
It lets you use kwargs for deps but just pass any regular positional arguments straight through.
Of course you want slightly less behaviour than our standard strategies (no accessors, etc.), but it might be a good starting point for you.
Nick Sutterer
@apotonick
Oct 23 2016 09:41
@timriley that's basically what i need. but: i don't event need you to override #initialize, as long as i get a hash via new, i'm happy
David Strauß
@stravid
Oct 23 2016 10:58
Hey everyone, I define my dry-validations schema and want to turn the output into a struct like object. Is there a trick to do this or do I have to repeat myself and define a dry-struct with the same attributes?
Tim Riley
@timriley
Oct 23 2016 11:41
Yes, if you want a struct with a certain set of attrs, @stravid, right now youll need to repeat yourself. In the future I think we'll look at imferring a validation schema from a dry-struct's attrs, but that's not the case right now.
In any case, by repeating the attrs at least you have the flexibility for each of the things to change slightly to best suit their particular use cases (input validatiom vs data modelling)
David Strauß
@stravid
Oct 23 2016 11:47
Thanks for the reply, in my case it's pure repetition since I deal with CQRS commands. The required input parameters map 1:1 to the resulting objects attributes :)
To be honest, I only want to turn the hash into an object so consuming application can do command.bla instead of command[:bla].
Oskar Szrajer
@gotar
Oct 23 2016 18:14
then you don't need nothing expect rom-repository it will map tulpe (hash) to object on the fly
Oskar Szrajer
@gotar
Oct 23 2016 18:26
the problem is when you need some specific struct, not 1:1 with db, then you need to repeat yourself
but it's CQRS it should be that way