Module: Vigilem::Core::Hooks

Includes:
Inheritable
Included in:
AbstractDevice
Defined in:
lib/vigilem/core/hooks.rb,
lib/vigilem/core/hooks/hook.rb,
lib/vigilem/core/hooks/utils.rb,
lib/vigilem/core/hooks/callback.rb,
lib/vigilem/core/hooks/inheritable.rb,
lib/vigilem/core/hooks/callback_proc.rb,
lib/vigilem/core/hooks/meta_callback.rb,
lib/vigilem/core/hooks/conditional_hook.rb

Overview

extend this

Defined Under Namespace

Modules: Callback, Inheritable, Utils Classes: CallbackProc, ConditionalHook, Hook, MetaCallback

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inheritable

#hooks, #inherited

Class Method Details

.extended(base) ⇒ Object

Parameters:

  • base


12
13
14
15
16
17
# File 'lib/vigilem/core/hooks.rb', line 12

def self.extended(base)
  # instance_level
  base.send(:define_method, :run_hook) do |hook_name, *args, &block|
    self.class.hooks.find {|hook| hook.name == hook_name }.run(self, *args, &block)
  end
end

Instance Method Details

#run_hook(hook_name, *args, &block) ⇒ Hook

class level finds a hook by that name and runs it

Parameters:

  • hook_name

    the hook to find

  • args (Array)

    arguments to be passed to the hook

  • block (Proc)

    Proc to be passed to the hook

Returns:



26
27
28
# File 'lib/vigilem/core/hooks.rb', line 26

def run_hook(hook_name, *args, &block)
  hooks.find {|hook| hook.name == hook_name }.run(self, *args, &block)
end