collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

When calling call! from another interactor merge context on failure #98

Closed att14 closed 7 years ago

att14 commented 9 years ago

Wanted to get an idea if something like this would be an acceptable change.

Basically, I would like to use an Interactor and do some extra work if the called Interactor is successful. Having call! update the calling context when Interactor::Failure is called makes this much cleaner. For example before you would write,

class Old
  include Interactor

  def call
    # do work
    result = Other.call
    if result.success?
      # do more work
    else
      context.fail!(...)
    end
  end
end

Now you do not have to check if the call was successful.

class New
  include Interactor

  def call
    # do work
    Other.call!
    # do more work
  end
end

Maybe this can be done in Organizers?

laserlemon commented 7 years ago

This code doesn't make it clear enough in my mind that anything is being merged. Plus, the call! method has been taken now so closing this for the time being.