Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for inheriting hooks #191

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kaspermeyer
Copy link

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
Copy link

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

@vsh91 vsh91 mentioned this pull request Feb 8, 2023
@emilyst
Copy link

emilyst commented Feb 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Callbacks are not inherited
3 participants