Class: Gollum::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/gollum-lib/hook.rb

Class Method Summary collapse

Class Method Details

.execute(type, *args) ⇒ Object


24
25
26
27
28
29
30
31
# File 'lib/gollum-lib/hook.rb', line 24

def execute(type, *args)
  type_hooks = @hooks[type]
  if type_hooks
    type_hooks.each_value do |block|
      block.call(*args)
    end
  end
end

.get(type, id) ⇒ Object


20
21
22
# File 'lib/gollum-lib/hook.rb', line 20

def get(type, id)
  @hooks.fetch(type, {})[id]
end

.register(type, id, &block) ⇒ Object


7
8
9
10
# File 'lib/gollum-lib/hook.rb', line 7

def register(type, id, &block)
  type_hooks     = @hooks[type] ||= {}
  type_hooks[id] = block
end

.unregister(type, id) ⇒ Object


12
13
14
15
16
17
18
# File 'lib/gollum-lib/hook.rb', line 12

def unregister(type, id)
  type_hooks = @hooks[type]
  if type_hooks
    type_hooks.delete(id)
    @hooks.delete(type) if type_hooks.empty?
  end
end