aaronmallen/activeinteractor

Update the wiki with inplace callbacks

aka-momo opened this issue · 2 comments

Elevator pitch, describe and sell us your feature request

As a developer,
I want be able to have documentation about in place Callbacks
so that I could use the functionality

Is your feature request related to a problem

see #247
see #246

Have you considered any alternatives

Additional Comments

I'm not able to update the wiki since it is open only for collabrators, Here is an example of what we can add to the inplace callbacks section:

We can do worker before or after perform which will be invoked on a specific interactor in an organizer by passing a block or passing a method name to the .organize method:

class MyInteractor1 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor1'
  end
end

class MyInteractor2 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor2'
  end
end

class MyOrganizer < ActiveInteractor::Organizer::Base
  organized do
    add MyInteractor1
    add MyInteractor2, before: -> { puts "Before" }, after: :print_after
  end

  private

  def print_after
    puts "After"
  end
end

MyOrganizer.perform
"MyInteractor1"
"Before"
"MyInteractor2"
"After"
#=> <MyOrganizer::Context...>

Thank you 🙏