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.



52
53
54
# File 'lib/clacky/extension/hook_loader.rb', line 52

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)


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

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



68
69
70
71
72
# File 'lib/clacky/extension/hook_loader.rb', line 68

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

.callbacksObject



64
65
66
# File 'lib/clacky/extension/hook_loader.rb', line 64

def callbacks
  @callbacks
end

.clear!Object



74
75
76
# File 'lib/clacky/extension/hook_loader.rb', line 74

def clear!
  @callbacks.clear
end