Class: Barista::Hooks

Inherits:
Object
  • Object
show all
Defined in:
lib/barista/hooks.rb

Instance Method Summary collapse

Constructor Details

#initializeHooks

Returns a new instance of Hooks.



4
5
6
# File 'lib/barista/hooks.rb', line 4

def initialize
  @callbacks = Hash.new { |h,k| h[k] = [] }
end

Instance Method Details

#has_hook?(name) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/barista/hooks.rb', line 19

def has_hook?(name)
  @callbacks.has_key?(name)
end

#invoke(name, *args) ⇒ Object



12
13
14
15
16
17
# File 'lib/barista/hooks.rb', line 12

def invoke(name, *args)
  @callbacks[name.to_sym].each do |callback|
    break if callback.call(*args) == false
  end
  nil
end

#on(name, &blk) ⇒ Object



8
9
10
# File 'lib/barista/hooks.rb', line 8

def on(name, &blk)
  @callbacks[name.to_sym] << blk
end