Sha256: 76a2273f25d24a9ac87ee8fcc9e23092e60649f1ef6be1095fc5378aa60bf56f

Contents?: true

Size: 431 Bytes

Versions: 1

Compression:

Stored size: 431 Bytes

Contents

module Barista
  class Hooks
    
    def initialize
      @callbacks = Hash.new { |h,k| h[k] = [] }
    end
    
    def on(name, &blk)
      @callbacks[name.to_sym] << blk
    end
    
    def invoke(name, *args)
      @callbacks[name.to_sym].each do |callback|
        break if callback.call(*args) == false
      end
      nil
    end
    
    def has_hook?(name)
      @callbacks.has_key?(name)
    end
            
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
barista-1.3.0 lib/barista/hooks.rb