interactor icon indicating copy to clipboard operation
interactor copied to clipboard

Callbacks are not inherited

Open aldesantis opened this issue 9 years ago • 6 comments

I'm rewriting my API layer to use interactors and I noticed callbacks defined on an interactor are not inherited by its children. Is this the desired behavior?

For the moment, this works fine:

class ParentInteractor
  def self.inherited(klass)
    klass.class_eval do
      # my hooks
    end
  end
end

aldesantis avatar Aug 13 '16 18:08 aldesantis

Could you write a test to expose this issue?

laserlemon avatar Mar 22 '17 01:03 laserlemon

I can confirm inheritance doesn't work on hooks. Any update on the fix?

aandis avatar Feb 21 '18 20:02 aandis

@aandis There are no updates on this from maintainers. But just yesterday, we solved this problem at our company using the method mentioned in the PR description (using inherited hooks) and it works well :)

manojmj92 avatar Feb 23 '18 06:02 manojmj92

Here is a test case:

require 'interactor'

class ABC
  include Interactor

  around :do_it

  def do_it(interactor)
    p "doing it"
    interactor.call
    p "done it"
  end
end

class DoIt < ABC
  def call
    p "calling DoIt"
  end
end

DoIt.call

class DoItAgain < ABC
  around :do_it

  def call
    p "calling DoItAgain"
  end
end

DoItAgain.call

Output:

"calling DoIt"
"doing it"
"calling DoItAgain"
"done it"

Expected Output:

"doing it"
"calling DoIt"
"done it"
"doing it"
"calling DoItAgain"
"done it"

Gemfile used:

source "https://rubygems.org"

gem "interactor"

att14 avatar Mar 08 '18 20:03 att14

+1, still an issue on the latest version 😕

iMacTia avatar Oct 07 '20 17:10 iMacTia

Still an issue 7 years later...

vitork avatar Apr 11 '23 14:04 vitork