I have an interactor that calls another interactor. So the situation is:
class MainInteractor
def call
...
result = SubInteractor.call(foo1: 'bar1', foo2: 'bar2', foo3: 'bar3')
if result. failure?
context.fail!(foo1: result.foo1, foo2: result.foo2, foo3: result.foo3) # or context.fail!(result.to_h)
else
...
end
...
end
end
It is so annoying to write result.to_h all time and looks dirty in the service.
Aprouch
Instead of passing the result by key/value or hash. I suggest parsing context={} to Hash. It helps to pass failed context between interactors.
Proc and Cons
Proc:
In the situation when the interactor has two or more levels of subcontractors. This is easy to pass a failed context and push it to the top.
Cons:
If you pass context all time, result context of top-level interactor will contain a lot of context attributes from all sub-interactors.
Problem
I have an interactor that calls another interactor. So the situation is:
It is so annoying to write
result.to_h
all time and looks dirty in the service.Aprouch
Instead of passing the result by key/value or hash. I suggest parsing
context={}
to Hash. It helps to pass failed context between interactors.Proc and Cons
Proc:
Cons: