Class: HookManager
- Inherits:
-
Object
- Object
- HookManager
- Includes:
- Singleton
- Defined in:
- lib/core_blur/hook_manager.rb
Instance Method Summary collapse
-
#initialize ⇒ HookManager
constructor
A new instance of HookManager.
- #register_hook(status, &block) ⇒ Object
- #trigger_hook(status, *args) ⇒ Object
Constructor Details
#initialize ⇒ HookManager
Returns a new instance of HookManager.
8 9 10 |
# File 'lib/core_blur/hook_manager.rb', line 8 def initialize @hooks = {} end |
Instance Method Details
#register_hook(status, &block) ⇒ Object
11 12 13 14 |
# File 'lib/core_blur/hook_manager.rb', line 11 def register_hook(status, &block) @hooks[status] ||= [] @hooks[status] << block end |
#trigger_hook(status, *args) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/core_blur/hook_manager.rb', line 15 def trigger_hook(status, *args) if @hooks[status] puts "\n执行hook阶段#{status}逻辑" @hooks[status].each { |hook| hook.call(*args) } end end |