These are chat archives for dry-rb/chat

17th
May 2018
Roland Laurès
@ShamoX
May 17 2018 08:19
Hi, I'm trying to use dry-validation and dry-struct together and got into a versions little problem.
Do you think that a new version of dry-validation will come up using dry-types 0.13 ? (I saw the master referee t it already)
I have then some warnings, but I don't know if I should open an issue or just discuss it in here.
Tim Riley
@timriley
May 17 2018 08:23
@ShamoX I think we’re planning to release something within the next month or so
Roland Laurès
@ShamoX
May 17 2018 08:24
ok, so I just wait ^^. Thanks @timriley
Also, what I'm doing is to mix both Struct and Validation into one class object that create the Validation schema inside the Class object and when instantiating a new object will first validate the hash and then pass it to Struct.new. If validation doesn't pass, it then raise a ValidationError containing all the messages of the Validation::Schema result (I use call). I don't know if it's worth sharing.
Nikita Shilnikov
@flash-gordon
May 17 2018 08:32
better to keep this concerns separated, validations usually happen on the edge of a system, rejecting invalid input as early as possible
mixing them usually end up with cumbersome code
Roland Laurès
@ShamoX
May 17 2018 08:54
Yeah, maybe you are right, I should perhaps consider keeping my data in the Hash instead of creating objects arborescence. But it's also a way to document and clarify a complexe interleaved/nested data model.
Nikita Shilnikov
@flash-gordon
May 17 2018 08:58
typical workflow: raw data (aka params, json) -> validation schema -> hash (usually) -> (init a struct | persist data). It usually turns out documenting complex cases through tests works better :)
Roland Laurès
@ShamoX
May 17 2018 09:02
I see, right point
(Maybe my thought are deformed by Rails model)
Roland Laurès
@ShamoX
May 17 2018 09:10
Yes, with your workflow, I just have to add an other step verifying the consistency of the data once it's in the struct, and then I can convert/treat it. Thanks for the tips.