collectiveidea / interactor

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

Callbacks are not inherited #114

Open aldesantis opened 8 years ago

aldesantis commented 8 years ago

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
laserlemon commented 7 years ago

Could you write a test to expose this issue?

aandis commented 6 years ago

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

manojmj92 commented 6 years ago

@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 :)

att14 commented 6 years ago

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"
iMacTia commented 4 years ago

+1, still an issue on the latest version 😕

vitork commented 1 year ago

Still an issue 7 years later...