Method: Interactor::Hooks::ClassMethods#before

Defined in:
lib/interactor/hooks.rb

#before(*hooks, &block) ⇒ Object

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

hooks - Zero or more Symbol method names representing instance methods

to be called before interactor invocation.

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

is executed after methods corresponding to any given Symbols.

Examples

class MyInteractor
  include Interactor

  before :set_start_time

  before do
    puts "started"
  end

  def call
    puts "called"
  end

  private

  def set_start_time
    context.start_time = Time.now
  end
end

Returns nothing.



88
89
90
91
# File 'lib/interactor/hooks.rb', line 88

def before(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| before_hooks.push(hook) }
end