class Statum::Hook
Hook
wrapper for Statum::Event
Public Class Methods
new(hook)
click to toggle source
Creates new Hook
instance
@param [Symbol, Proc] hook Callable object or symbol that represents instance method
# File lib/statum/hook.rb, line 7 def initialize(hook) @hook = hook end
Public Instance Methods
evaluate(instance)
click to toggle source
Execute hook on instane
@param [Object] instance Class instance
# 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
Private Instance Methods
find_hook(instance)
click to toggle source
Finds hook on instance
@param [Object] instance Instance of class that included Statum
@return [Proc]
# File lib/statum/hook.rb, line 31 def find_hook(instance) @hook.respond_to?(:call) ? @hook : instance.method(@hook) end