module Interaktor::Hooks::ClassMethods

Internal: Interaktor::Hooks class methods.

Public Instance Methods

after(*hooks, &block) click to toggle source

Public: Declare hooks to run after Interaktor 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 interaktor 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 MyInteraktor
  include Interaktor

  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.

# File lib/interaktor/hooks.rb, line 124
def after(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| after_hooks.unshift(hook) }
end
after_hooks() click to toggle source

Internal: An Array of declared hooks to run before Interaktor invocation. The hooks appear in the order in which they will be run.

Examples

class MyInteraktor
  include Interaktor

  after :set_finish_time, :say_goodbye
end

MyInteraktor.after_hooks
# => [:say_goodbye, :set_finish_time]

Returns an Array of Symbols and Procs.

# File lib/interaktor/hooks.rb, line 182
def after_hooks
  @after_hooks ||= []
end
around(*hooks, &block) click to toggle source

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

hooks - Zero or more Symbol method names representing instance methods

to be called around interaktor invocation. Each instance method
invocation receives an argument representing the next link in
the around hook chain.

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 MyInteraktor
  include Interaktor

  around :time_execution

  around do |interaktor|
    puts "started"
    interaktor.call
    puts "finished"
  end

  def call
    puts "called"
  end

  private

  def time_execution(interaktor)
    context.start_time = Time.now
    interaktor.call
    context.finish_time = Time.now
  end
end

Returns nothing.

# File lib/interaktor/hooks.rb, line 50
def around(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| around_hooks.push(hook) }
end
around_hooks() click to toggle source

Internal: An Array of declared hooks to run around Interaktor invocation. The hooks appear in the order in which they will be run.

Examples

class MyInteraktor
  include Interaktor

  around :time_execution, :use_transaction
end

MyInteraktor.around_hooks
# => [:time_execution, :use_transaction]

Returns an Array of Symbols and Procs.

# File lib/interaktor/hooks.rb, line 144
def around_hooks
  @around_hooks ||= []
end
before(*hooks, &block) click to toggle source

Public: Declare hooks to run before Interaktor 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 interaktor 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 MyInteraktor
  include Interaktor

  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.

# File lib/interaktor/hooks.rb, line 87
def before(*hooks, &block)
  hooks << block if block
  hooks.each { |hook| before_hooks.push(hook) }
end
before_hooks() click to toggle source

Internal: An Array of declared hooks to run before Interaktor invocation. The hooks appear in the order in which they will be run.

Examples

class MyInteraktor
  include Interaktor

  before :set_start_time, :say_hello
end

MyInteraktor.before_hooks
# => [:set_start_time, :say_hello]

Returns an Array of Symbols and Procs.

# File lib/interaktor/hooks.rb, line 163
def before_hooks
  @before_hooks ||= []
end