collectiveidea / interactor

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

Question Regarding Behaviour of hooks with a fail! #72

Closed hookercookerman closed 10 years ago

hookercookerman commented 10 years ago

based on the fact that after blocks are only called for successful intereractor calls; should rolback be given the same dsl love? (failure) or should we be explicit on the callback naming here; cos what we are saying is after_success.

just a thought

also prehaps I want to be able to define more then 1 rollback the same as I can with an after hook

laserlemon commented 10 years ago

Thank you for the suggestion! Let me explain the rationale I've been using when deciding between macro or instance methods.

The before, after and around macro methods were not added as a matter of style. They were needed in order to apply more than one hook of a given type to the same interactor. That couldn't be done by defining before, after and around instance methods on the interactor.

The call and rollback methods are different. Interactors are meant to be single purpose classes so Interactor's design decisions will reflect that intention. That's why interactors can use a call instance method. There should only ever be one thing that any given interactor does and that's encapsulated in call. The rollback method is the inverse. Whatever call does, rollback undoes.

Also, one should not think of after as after_success and rollback as after_failure. Both are only invoked for interactors that have already succeeded.

I hope that makes sense! You do raise a great question about whether an after-failure hook might be useful. I'll close this issue but feel free to continue the after-failure conversation here. Thank you! :clap:

hookercookerman commented 10 years ago

cool yep all makes sense cheers; would be nice to have after_failure; failures can happen just as much as a success can, whilst I can create custom fail methods and include via a module aka fail tracking; it would be nice to leverage the same patterns I would use for success cases; thanks

laserlemon commented 10 years ago

Great, that's fantastic feedback. Thank you! We'll certainly talk more about this.

mjbellantoni commented 9 years ago

:+1: To after_failure. In my use case, I'm trying to send observers a message that the action failed. I can do this manually in a plain old Interactor but not with an Organizer (unless I monkey patch.)