These are chat archives for dry-rb/chat

4th
Nov 2016
Uros Jurglic
@jurglic
Nov 04 2016 12:23
Hi guys! I'm new to dry-transaction gem, and I need an advice
Screen Shot 2016-11-04 at 13.22.26.png
^^ We have a transaction defined like this
Now the business requirement changed so that first three operations need to be run always - regardless of the result of the previous operation.
What would be the right way to approach in dry transaction?
Piotr Solnica
@solnic
Nov 04 2016 12:39
@jurglic then it’s no longer a transaction :)
Uros Jurglic
@jurglic
Nov 04 2016 12:41
Yeah, that crossed my mind too!
@solnic But if we forget that one for a minute... would something like that make more sense?
Screen Shot 2016-11-04 at 13.44.04.png
Piotr Solnica
@solnic
Nov 04 2016 12:46
@jurglic it does
Uros Jurglic
@jurglic
Nov 04 2016 12:47
Can the first three operations still use Either response? Or will it fail if one of them returns Left?
@jurglic
Uros Jurglic
@jurglic
Nov 04 2016 12:59
Is that so even if step is defined as map :qc_silence?
Thanks
Nikita Shilnikov
@flash-gordon
Nov 04 2016 13:01
the only place where step adapter is used is here https://github.com/dry-rb/dry-transaction/blob/master/lib/dry/transaction/step.rb#L36 so your step have to return a Right instance always
Uros Jurglic
@jurglic
Nov 04 2016 13:03
Sorry it's a bit confusing to me. So if I use map :qc_silence, the QcSilence should never return Left?
Nikita Shilnikov
@flash-gordon
Nov 04 2016 13:05
no worries, well, map always returns Right so it should work just fine for you :) BUT there is a caveat
if you return Left/Right from QcSilence, map will wrap it once again
so you'll get Right(Right(...)) or Right(Left(...))
Uros Jurglic
@jurglic
Nov 04 2016 13:06
Aha, I see.
Piotr Solnica
@solnic
Nov 04 2016 13:08
according to docs, map always returns Right
Uros Jurglic
@jurglic
Nov 04 2016 13:08
So you think my approach is somewhat acceptable? :D
@solnic Thanks Piotr yeah I saw that one, that's why I was confused before.
Piotr Solnica
@solnic
Nov 04 2016 13:10
feels like an overhead though, if it always returns Right then maybe it’d be better to just pass plain values
Uros Jurglic
@jurglic
Nov 04 2016 13:12
So the first 3 operations, - as implemented now - can return Left or Right. However they are independent. And now new requirement came they should run always no matter if any of them failed in a previous step.
So I'm trying to figure out what's the approach best aligned with dry-transaction.
Tim Riley
@timriley
Nov 04 2016 20:11
Right now, it feels like it's be better just to run those three things in a custom class
@apotonick's pipetree stuff in trailblazer 2 makes me want to enrich some of the functionality of dry-transaction, but in a little while
Nick Sutterer
@apotonick
Nov 04 2016 20:16
@timriley i was evaluating it
and decided to use my own pipetree stuff that is approved to work in representable, and is super fast
it's very important for that to be fast, since i want to use pipetree for all my gems and everything
we should probably "merge" those two gems
Nick Sutterer
@apotonick
Nov 04 2016 20:27
@timriley question reg. dry-matcher. so, when i define using Matcher.new that's called the matcher object?
and when i evaluate it, how's that named?
and, what are you doing awake at 7am on a sunny saturday?
Tim Riley
@timriley
Nov 04 2016 20:48
Kids :p
Yeah, I guess Matcher.new makes the matcher object, and then you run it with a a "match block" against some kind of value
/me will think about those names a little more
Steve
@dnd
Nov 04 2016 20:58
is there a way to get the errors from dry-validation as symbols/keys instead of text sentences? I'm looking to get output like {amount: [:missing, :min_size]} or something like that
Nick Sutterer
@apotonick
Nov 04 2016 21:13
@timriley "match block", i just called it handler, but yeah
Martín Fernández
@bilby91
Nov 04 2016 21:14
Hello, do I need to require something in order to use Types::Maybe ?
Tim Riley
@timriley
Nov 04 2016 21:16
Yeah, it's an "extension" now, @bilby91 - I'm on my phone right now but if you grep the specs for :maybe, you should see how it's done.
Martín Fernández
@bilby91
Nov 04 2016 21:16
Perfect! Will check
Thanks @timriley

Is this correct ?

# frozen_string_literal: true
class User < Dry::Struct
  attribute :id, Types::Strict::Int
  attribute :source_url, Types::Strict::String
  attribute :width, Types::Maybe::Float
  attribute :height, Types::Maybe::Float
  attribute :format, Types::Maybe::String
end

I’m getting NameError: Float cannot be autoloaded from an anonymous class or module

Nick Sutterer
@apotonick
Nov 04 2016 21:24
@bilby91 did you require the types file?
Tim Riley
@timriley
Nov 04 2016 21:24
I've never seen this error. Are you using this inside Rails?
Yeah, you might want to explicitly require the file where you set up the Types module
Nick Sutterer
@apotonick
Nov 04 2016 21:24
@timriley how can i know whether or not a matcher has executed a "handler"?
Martín Fernández
@bilby91
Nov 04 2016 21:24
My bad, I was missing Strict or Coercible on the Maybe types
I’m working on a rails project
Tim Riley
@timriley
Nov 04 2016 21:25
@apotonick how do you mean?
Nick Sutterer
@apotonick
Nov 04 2016 21:25
@timriley matcher.(result) #=> no handler was found ? how do i know
add my own handler?
Tim Riley
@timriley
Nov 04 2016 21:25
Ahh. Hmm, there no authoritative way to know right now.
Nick Sutterer
@apotonick
Nov 04 2016 21:26
@timriley could we add a special return value at some point? not too important right now
Tim Riley
@timriley
Nov 04 2016 21:26
Yeah, we could look at something like that.
Nick Sutterer
@apotonick
Nov 04 2016 21:26
just designing the Endpoint API for Trailblazer
Tim Riley
@timriley
Nov 04 2016 21:26
Another way to do it is to make sure you have enough cases defined to cover all potential inputs
Nick Sutterer
@apotonick
Nov 04 2016 21:26
yeah but i'm making it customizable
Tim Riley
@timriley
Nov 04 2016 21:26
The marcher won't let you pass a match block that is inexhaustive
Martín Fernández
@bilby91
Nov 04 2016 21:27
When using Maybe it is required to add the optional keys on the initializer hash ?
Nick Sutterer
@apotonick
Nov 04 2016 21:27
we have a default matcher provided by TRB, and then the user can have another
Tim Riley
@timriley
Nov 04 2016 21:27
I.e. It'll require you have at least one of each case
Steve
@dnd
Nov 04 2016 21:27
@timriley is there any way to do my question above regarding dry-validation errors?
Nick Sutterer
@apotonick
Nov 04 2016 21:29
@dnd we will sort this out in reform soon, the dry-v/errors API
Tim Riley
@timriley
Nov 04 2016 21:35
@dnd there should be a way, the error strings are compiled from raw data after all - can you post your question on discuss.dry-rb.org?
@apotonick mind filing a GH issue about indicating when a matched block has been run and no case has matched?
Nick Sutterer
@apotonick
Nov 04 2016 21:36
@timriley thanks, will do when the Endpoint draft is running
Tim Riley
@timriley
Nov 04 2016 21:38
👍🏼
Nikita Shilnikov
@flash-gordon
Nov 04 2016 21:50
@bilby91 Maybe types should behave as Default, so whether keys are mandatory or not depends on what constructor_type you use
Martín Fernández
@bilby91
Nov 04 2016 21:52
@flash-gordon Is there any doc on how the constructors work ?
Nick Sutterer
@apotonick
Nov 04 2016 21:52
my favorite question haha
Martín Fernández
@bilby91
Nov 04 2016 21:52
jja
Nick Sutterer
@apotonick
Nov 04 2016 21:52
i get it asked around 10x a week
Martín Fernández
@bilby91
Nov 04 2016 21:53
:( sorry to be one of them!
Nikita Shilnikov
@flash-gordon
Nov 04 2016 21:54
@bilby91 here dry-rb/dry-rb.org#104 :P
Martín Fernández
@bilby91
Nov 04 2016 21:54
Crystal clear now :)
Nick Sutterer
@apotonick
Nov 04 2016 21:57
crystal?
Martín Fernández
@bilby91
Nov 04 2016 21:58
@apotonick like super clear what type of constructor_types are ? :)
Nick Sutterer
@apotonick
Nov 04 2016 22:01
@bilby91 got it :P