class PatronusFati::EventHandler
Public Instance Methods
event(asset_type, event_type, msg, optional = {})
click to toggle source
# File lib/patronus_fati/event_handler.rb, line 23 def event(asset_type, event_type, msg, optional = {}) handlers_for(asset_type, event_type).each { |h| h.call(asset_type, event_type, msg, optional) } end
handlers()
click to toggle source
# File lib/patronus_fati/event_handler.rb, line 3 def handlers @handlers ||= {} end
handlers_for(asset_type, event_type)
click to toggle source
# File lib/patronus_fati/event_handler.rb, line 7 def handlers_for(asset_type, event_type) handlers[asset_type] ||= (asset_type == :any ? [] : {}) Array(handlers[:any]) | Array(handlers[asset_type][:any]) | Array(handlers[asset_type][event_type]) end
on(asset_type, event_type = :any, &handler)
click to toggle source
# File lib/patronus_fati/event_handler.rb, line 12 def on(asset_type, event_type = :any, &handler) if asset_type == :any handlers[:any] ||= [] handlers[:any].push(handler) else handlers[asset_type] ||= {} handlers[asset_type][event_type] ||= [] handlers[asset_type][event_type].push(handler) end end