dry-transaction icon indicating copy to clipboard operation
dry-transaction copied to clipboard

Allow matching by class instead of just step_name

Open andrepcg opened this issue 3 years ago • 1 comments

Describe the bug

When calling a transaction with a block I can't match the result by the failure class and only by the name of the step.

To Reproduce

class TestOp
  include Dry::Transaction

  step :validate

  def validate(input)
    Contract.new.call(**input).to_monad
  end
end

TestOp.new.call({}) do |m|
  m.failure(Dry::Validation::Result) do |validation|
    # ... <- doesn't match here
  end

  m.failure do
    # ... <- it matches here
  end

Expected behavior

It should match by the resulting class and not just by the step name.

However, if I don't call it with a block and instead I pattern match the result, it works as intended.

op = TestOp.new.call({})
case op
in Dry::Monads::Failure(Dry::Validation::Result => validation)
  # <- it reaches here
end

My environment

  • Affects my production application: NO
  • Ruby version: 2.7.2
  • OS: debian

andrepcg avatar Nov 09 '21 17:11 andrepcg

Is this issue been taken up, if not I would like to pick it up and fix it?

saksham-jain avatar Jul 11 '22 11:07 saksham-jain