collectiveidea / interactor

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

Add support for inheriting hooks #191

Open kaspermeyer opened 4 years ago

kaspermeyer commented 4 years ago

This PR implements support for inheriting hooks defined in ancestors.

A previous PR has also targeted this issue; however, that solution does not support hooks declared in ancestors at runtime. This solution does:

class ParentInteractor
  include Interactor
end

class ChildInteractor < ParentInteractor
end

ParentInteractor.before do
  puts "Before in parent"
end

ChildInteractor.call 
=> "Before in parent"

I had to move around the internals of the Hooks module a bit to make this work, which might break things, should people attempt to mutate the values of #around_hooks, #before_hooks and #after_hooks in their applications. I hope this is acceptable if we target this fix for the next major version, which seems to be 4.0.

Let me know if I'm missing anything.

Fixes: #114

tsuwatch commented 3 years ago

Could you review this if you get a chance? @gaffneyc @danielmorrison

emilyst commented 9 months ago

This is really nice, and I'd support seeing this merged as well.