Module: Clacky::ExtensionHookLoader
- Defined in:
- lib/clacky/extension/hook_loader.rb
Overview
Loads Ruby hook files contributed by ext.yml containers
(contributes.hooks: [{ event, file }]). Each file is required once at
process start; it registers callbacks via Clacky::ExtensionHookRegistry.add.
Every agent then copies those callbacks onto its own HookManager during
init, so each agent gets its own isolated hook chain.
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Class Method Details
.last_result ⇒ Object
37 38 39 |
# File 'lib/clacky/extension/hook_loader.rb', line 37 def self.last_result @last_result || load_all end |
.load_all ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/clacky/extension/hook_loader.rb', line 12 def self.load_all result = Result.new(registered: [], skipped: []) units = Array(Clacky::ExtensionLoader.last_result&.hooks) units.each do |unit| event = unit.spec["event"].to_sym unless Clacky::HookManager::HOOK_EVENTS.include?(event) msg = "unknown event: #{event}" result.skipped << [unit.id, msg] Clacky::Logger.warn("[ExtensionHookLoader] #{unit.ext_id}/#{unit.id}: #{msg}") next end Clacky::ExtensionHookRegistry.current_event = event require unit.spec["file_abs"] result.registered << [unit.ext_id, unit.id, event] rescue StandardError, ScriptError => e result.skipped << [unit.id, e.] Clacky::Logger.warn("[ExtensionHookLoader] #{unit.ext_id}/#{unit.id}: #{e.}") ensure Clacky::ExtensionHookRegistry.current_event = nil end @last_result = result result end |