These are chat archives for dry-rb/chat

18th
Sep 2017
Alexander
@cutalion
Sep 18 2017 16:49
chat, how do you debug dry-validation rules? binding.pry or puts don't work inside the rule block
Piotr Solnica
@solnic
Sep 18 2017 17:30
@cutalion ::Kernel.binding.pry
what do you want to debug though? these blocks only build up rule ast
it's not run-time logic
Alexander
@cutalion
Sep 18 2017 18:49
When complex rule doesn't work I try to figure out why. Dump parameters check out scope /context. Thanks for the tip!
Rafael George
@cored
Sep 18 2017 19:22
is it possible to define a custom constructor for a dry-type
I'm generating data from an xml so I'm using nokogiri to extract the value from the node, I would like to have a custom constructor to do node.text to instantiate the data properly for a particular value object
it will be easier for me to reuse those custom types and compose bigger types that way, I'm resorting to a custom factory method name ValueObject.for()
Nikita Shilnikov
@flash-gordon
Sep 18 2017 19:24
Types::Strict::String.constructor { |node| node.text } <- @cored
Rafael George
@cored
Sep 18 2017 19:24
nice
thanks
Nikita Shilnikov
@flash-gordon
Sep 18 2017 19:25
:+1:
Rafael George
@cored
Sep 18 2017 19:47
it could be nice to have a constructor type xml
and just pass a nokogiri document and then that dry struct do the same thing as with constructor schema with json
is that even possible @flash-gordon ?
Nikita Shilnikov
@flash-gordon
Sep 18 2017 19:54
to some extent, not OOTB atm, you'll have to create your own subclass for that, say XMLStruct or something. It would take attribute keys, an input xml and map them together
Rafael George
@cored
Sep 18 2017 19:55
right, yes I'm doing that right now
with a .for method to parse the xml and map them to the appropiate field
I wanted to know about the constructor thing to not repeat myself every time I tried to instantiate a custom type that requires xml
however when using the custom constructor facilities I end up with a problem in which the constructor is not consistent, if someone pass an string they will be force to wrap the value of that string inside a node if I keep using the mapping in the custom field
I decided to revert this change and leave a little bit parsing duplication for now
so not having the .constructor { |node| node.text } thing in it
ifyou do Type.new("string") that will fail
Nikita Shilnikov
@flash-gordon
Sep 18 2017 20:24
it's up to you, the constructor could have coercion logic if you need