Module: Hookable::ClassMethods

Defined in:
lib/hookable.rb

Instance Method Summary collapse

Instance Method Details

#disable_hook(*hook_names) ⇒ Object



88
89
90
# File 'lib/hookable.rb', line 88

def disable_hook *hook_names
  self.disabled_hooks = hook_names
end

#hook_declare(name, *groups) ⇒ Object

FIXME handle groups



93
94
95
# File 'lib/hookable.rb', line 93

def hook_declare name, *groups # FIXME handle groups
  self.hooks = [name]
end

#hook_trigger(name, *args, &block) ⇒ Object

Raises:

  • (ArgumentError)


67
68
69
70
71
72
73
74
# File 'lib/hookable.rb', line 67

def hook_trigger name, *args, &block
  raise ArgumentError, "Unknown hook #{name}" unless hooks.include? name
  return if disabled_hooks.include? name
  hookers.each do |hooker|
    Internal.hook_trigger(hooker, name, *args, &block)
  end
  self
end

#hooker_subscribe(hooker) ⇒ Object



77
78
79
80
# File 'lib/hookable.rb', line 77

def hooker_subscribe hooker
  self.hookers = [hooker]
  self
end

#subscribe_hook(*hook_names, &block) ⇒ Object



83
84
85
# File 'lib/hookable.rb', line 83

def subscribe_hook *hook_names, &block
  hooker_subscribe ProcHooker.new(*hook_names, &block)
end