Class: ActiveEvent::SSE
- Inherits:
-
Object
- Object
- ActiveEvent::SSE
- Defined in:
- lib/active_event/sse.rb
Instance Method Summary collapse
- #close ⇒ Object
- #data(data) ⇒ Object
- #event(event, data = nil, options = {}) ⇒ Object
-
#initialize(io) ⇒ SSE
constructor
A new instance of SSE.
Constructor Details
#initialize(io) ⇒ SSE
Returns a new instance of SSE.
5 6 7 |
# File 'lib/active_event/sse.rb', line 5 def initialize(io) @io = io end |
Instance Method Details
#close ⇒ Object
22 23 24 |
# File 'lib/active_event/sse.rb', line 22 def close @io.close end |
#data(data) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/active_event/sse.rb', line 13 def data(data) data.each_pair do |key, value| (value+"\n").split("\n", -1)[0..-2].each do |v| @io.write "#{key}: #{v}\n" end end @io.write "\n" end |
#event(event, data = nil, options = {}) ⇒ Object
9 10 11 |
# File 'lib/active_event/sse.rb', line 9 def event(event, data = nil, = {}) self.data .merge(event: event, data: JSON.dump(data)) end |