Class: ActiveEvent::SSE

Inherits:
Object
  • Object
show all
Defined in:
lib/active_event/sse.rb

Instance Method Summary collapse

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

#closeObject



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, options = {})
  self.data options.merge(event: event, data: JSON.dump(data))
end