Class: Statum::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/statum/hook.rb

Overview

Hook wrapper for Statum::Event

Instance Method Summary collapse

Constructor Details

#initialize(hook) ⇒ Hook

Creates new Hook instance

Parameters:

  • hook (Symbol, Proc)

    Callable object or symbol that represents instance method



7
8
9
# File 'lib/statum/hook.rb', line 7

def initialize(hook)
  @hook = hook
end

Instance Method Details

#evaluate(instance) ⇒ Object

Execute hook on instane

Parameters:

  • instance (Object)

    Class instance



14
15
16
17
18
19
20
21
22
# File 'lib/statum/hook.rb', line 14

def evaluate(instance)
  return if @hook.nil?
  hook = find_hook(instance)
  if hook.arity.zero?
    instance.instance_exec(&hook)
  else
    instance.instance_exec(instance, &hook)
  end
end