Sha256: 3f393a4446e4dbd6c6b1f29a3c8530ef97f60f50d7cd5c547548f4330f917e34

Contents?: true

Size: 845 Bytes

Versions: 14

Compression:

Stored size: 845 Bytes

Contents

module Hooks
  @@hooks = {}
  
  def fire(data, *events)
    #puts "Hooks: #{@@hooks.inspect}"
    #puts "Events: #{events.inspect}"
    #puts "\twith data: #{data.inspect}"
    unless @@hooks[:global].nil?
      @@hooks[:global].call(data, 'global')
    end
    
    if events.length > 0
      events.each do |event|
        #print "Checking for event: #{event} in hooks..."
        if @@hooks[event].nil?
          #puts "not found, ignoring."
        else
          #puts "found, firing!"
          @@hooks[event].call(data, event)
        end
      end
    end
  end
  
  def listen *events, &block
    #puts "Listening for #{events.inspect}"

    if events.empty? and block_given?
      @@hooks[:global] = block
    elsif !events.nil? and block_given?
      events.each do |event|
        @@hooks[event] = block
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
cloudfuji-0.0.46 lib/hooks.rb
cloudfuji-0.0.45 lib/hooks.rb
cloudfuji-0.0.44 lib/hooks.rb
cloudfuji-0.0.43 lib/hooks.rb
cloudfuji-0.0.42 lib/hooks.rb
cloudfuji-0.0.41 lib/hooks.rb
cloudfuji-0.0.40 lib/hooks.rb
cloudfuji-0.0.39 lib/hooks.rb
cloudfuji-0.0.38 lib/hooks.rb
cloudfuji-0.0.37 lib/hooks.rb
bushido-0.0.36 lib/hooks.rb
bushido-0.0.35 lib/bushido/hooks.rb
bushido-0.0.34 lib/bushido/hooks.rb
bushido-0.0.33 lib/bushido/hooks.rb