Sha256: 855fd889f80ab8c20ea8ee3ab777ff45fc03ce57ce47d14f01c587e85359af25

Contents?: true

Size: 353 Bytes

Versions: 11

Compression:

Stored size: 353 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
    
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
barista-1.2.1 lib/barista/hooks.rb
barista-1.2.0 lib/barista/hooks.rb
barista-1.1.0 lib/barista/hooks.rb
barista-1.1.0.pre1 lib/barista/hooks.rb
barista-1.0.0 lib/barista/hooks.rb
barista-0.7.0.pre3 lib/barista/hooks.rb
barista-0.7.0.pre2 lib/barista/hooks.rb
barista-0.6.1 lib/barista/hooks.rb
barista-0.6.0 lib/barista/hooks.rb
barista-0.5.1 lib/barista/hooks.rb
barista-0.5.0 lib/barista/hooks.rb