Module: Loco::Emitter
- Included in:
- NotificationCenter
- Defined in:
- lib/loco/emitter.rb
Instance Method Summary collapse
- #add_hub(name, members = []) ⇒ Object
- #del_hub(name) ⇒ Object
- #emit(obj, event = nil, opts = {}) ⇒ Object
- #emit_to(recipient_s, data) ⇒ Object
- #get_hub(name) ⇒ Object
Instance Method Details
#add_hub(name, members = []) ⇒ Object
18 19 20 |
# File 'lib/loco/emitter.rb', line 18 def add_hub(name, members = []) Hub.set(name, members) end |
#del_hub(name) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/loco/emitter.rb', line 26 def del_hub(name) hub = Hub.get(name) return false if hub.nil? hub.destroy end |
#emit(obj, event = nil, opts = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/loco/emitter.rb', line 5 def emit(obj, event = nil, opts = {}) Broadcaster.( obj, event, payload: opts[:payload] || opts[:data], recipients: opts[opts[:for] ? :for : :to] ) end |
#emit_to(recipient_s, data) ⇒ Object
14 15 16 |
# File 'lib/loco/emitter.rb', line 14 def emit_to(recipient_s, data) Sender.(recipient_s, data) end |
#get_hub(name) ⇒ Object
22 23 24 |
# File 'lib/loco/emitter.rb', line 22 def get_hub(name) Hub.get(name) end |