Class: PatronusFati::EventHandler
- Inherits:
-
Object
- Object
- PatronusFati::EventHandler
- Defined in:
- lib/patronus_fati/event_handler.rb
Instance Method Summary collapse
- #event(asset_type, event_type, msg, optional = {}) ⇒ void
- #handlers ⇒ void
- #handlers_for(asset_type, event_type) ⇒ void
- #on(asset_type, event_type = :any, &handler) ⇒ void
Instance Method Details
#event(asset_type, event_type, msg, optional = {}) ⇒ void
23 24 25 |
# 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 ⇒ void
3 4 5 |
# File 'lib/patronus_fati/event_handler.rb', line 3 def handlers @handlers ||= {} end |
#handlers_for(asset_type, event_type) ⇒ void
7 8 9 10 |
# 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) ⇒ void
12 13 14 15 16 17 18 19 20 21 |
# 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 |