These are chat archives for dry-rb/chat

18th
Jan 2018
Lance Carlson
@lancecarlson
Jan 18 2018 15:50
Hi all! I'm currently investigating whether usage of dry-types for making a client library to an API
I was thinking about possibly leveraging json schema to specify the requests and responses, and perhaps havingn dry-types do the coersion.
does anyone have much experience using dry-types in client libraries ?
Lance Carlson
@lancecarlson
Jan 18 2018 15:57
ohh I just found dry-schema
can I use this to coerce values?
Piotr Solnica
@solnic
Jan 18 2018 16:17
@lancecarlson dry-schema is not released yet, it's partial extraction from dry-validation (and a rewrite). for now, you can just use dry-validation, it supports coercion
Lance Carlson
@lancecarlson
Jan 18 2018 16:32
@solnic can I see an example of coercion?
Piotr Solnica
@solnic
Jan 18 2018 16:36
@lancecarlson it's inferred from your type expectations, so it works automatically, when you use Form or JSON schemas
Lance Carlson
@lancecarlson
Jan 18 2018 17:00
@solnic gotcha, I think I'm good to go with I get back to my machine. Do you think a good use case for this would be to verify request parameters for a client library and then to coerce values from a response body?
Piotr Solnica
@solnic
Jan 18 2018 17:01
@lancecarlson yes
Lance Carlson
@lancecarlson
Jan 18 2018 17:01
So cool
All client libraries should use it! :)
Great work BTW. I'm excited to dig in
Stergio
@stergiom
Jan 18 2018 19:32
Assuming the case of a Dry::Struct class that points to a different Dry::Struct class as a type for one of its attributes, the depended upon class would have to be required first. What is the preffered approach to managing such dependecies –or in the least an approach that anyone has come across that works well?
Nikita Shilnikov
@flash-gordon
Jan 18 2018 19:49
@stergiom I doubt this, many things get broken when it comes to circular dependencies, dry-struct is no exception. However, ruby is flexible enough for this since it allows reopening a class, thus, you can load attribute-less definitions first, then load the rest of them. In practice, this means you put require right after class MyStruct < Dry::Struct
but after all I wouldn't go this way :)
Stergio
@stergiom
Jan 18 2018 20:00
ahh.. that is an interesting approach, why wouldn't you go this way @flash-gordon ?
Nikita Shilnikov
@flash-gordon
Jan 18 2018 20:10
because circular dependencies is a smell, ofc I don't know your case but I'd aviod them because they may lead to unpredictable/unsolvable problems similar to this one^
Stergio
@stergiom
Jan 18 2018 20:33
so stick to explict require's where necessary then :thumbsup: