These are chat archives for dry-rb/chat

15th
Dec 2016
Tim Riley
@timriley
Dec 15 2016 05:08
@polmiro I haven’t run into someone using dry-transaction with objects like yours before. I’d really recommend against setting your input as state via the initializer, because that means your objects become stateful, non-reusable, and you effectively have to throw them away after #call-ing them once.
the kind of object that dry-transaction is designed to work with is one that receives static things in its initializer (config or collaborating objects, i.e. things that never need to change), and then #call is receives the variable input.
This means you can have the same object and #call on it many times over.
As for (2), there’s actually a “monads” extension for dry-validation that lets you return either objects: https://github.com/dry-rb/dry-validation/blob/master/lib/dry/validation/extensions/monads.rb
you could provie a base validation schema class for your app with a #call method that does that to_either conversion for you
(or I suppose write a step adapter to do it)
Pol Miro
@polmiro
Dec 15 2016 16:57
cool that makes sense, thanks for the explanation Tim :thumbsup:
Pol Miro
@polmiro
Dec 15 2016 17:04
it's great to hear about that monads extension, did not realize it existed
Pol Miro
@polmiro
Dec 15 2016 18:01
where could I find more usage examples of dry-transaction?