Method: Interactor::Hooks::ClassMethods#after

Defined in:
lib/interactor/hooks.rb

#after(*hooks, &block) ⇒ Object

Public: Declare hooks to run after Interactor invocation. The after method may be called multiple times; subsequent calls prepend declared hooks to existing after hooks.

hooks - Zero or more Symbol method names representing instance methods

to be called after interactor invocation.

block - An optional block to be executed as a hook. If given, the block

is executed before methods corresponding to any given Symbols.

Examples

class MyInteractor
  include Interactor

  after :set_finish_time

  after do
    puts "finished"
  end

  def call
    puts "called"
  end

  private

  def set_finish_time
    context.finish_time = Time.now
  end
end

Returns nothing.



125
126
127
128
# File 'lib/interactor/hooks.rb', line 125

def after(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| after_hooks.unshift(hook) }
end