Class: HookManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/core_blur/hook_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeHookManager

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