Module: Clacky::ExtensionHookRegistry

Defined in:
lib/clacky/extension/hook_loader.rb

Overview

Process-wide registry for ext-contributed hook callbacks. Callbacks are registered once at file load time; each new agent copies them onto its own HookManager during init via apply_to.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.current_eventObject

Returns the value of attribute current_event.



50
51
52
# File 'lib/clacky/extension/hook_loader.rb', line 50

def current_event
  @current_event
end

Class Method Details

.add(event = nil, &block) ⇒ Object

Register a callback. event falls back to the loader-set context so ext hook files can call add { ... } without repeating the event name already declared in ext.yml.

Raises:

  • (ArgumentError)


55
56
57
58
59
60
# File 'lib/clacky/extension/hook_loader.rb', line 55

def add(event = nil, &block)
  ev = (event || @current_event)
  raise ArgumentError, "ExtensionHookRegistry.add called outside a hook file" unless ev

  @callbacks[ev.to_sym] << block
end

.apply_to(hook_manager) ⇒ Object



66
67
68
69
70
# File 'lib/clacky/extension/hook_loader.rb', line 66

def apply_to(hook_manager)
  @callbacks.each do |event, blocks|
    blocks.each { |b| hook_manager.add(event, &b) }
  end
end

.callbacksObject



62
63
64
# File 'lib/clacky/extension/hook_loader.rb', line 62

def callbacks
  @callbacks
end

.clear!Object



72
73
74
# File 'lib/clacky/extension/hook_loader.rb', line 72

def clear!
  @callbacks.clear
end