Sha256: d9aabaf572573de9b5bc4b1fea298973f90de3a4b0df17e285443b077154ad68
Contents?: true
Size: 632 Bytes
Versions: 10
Compression:
Stored size: 632 Bytes
Contents
module Rasti module Web class ServerSentEvent < String attr_reader :data, :id, :event private def initialize(data, options={}) @data = data @id = options[:id] @event = options[:event] super serialize end def serialize serialized_data = data.respond_to?(:to_json) ? data.to_json : data.to_s message = '' message << "id: #{id}\n" if id message << "event: #{event}\n" if event serialized_data.split("\n").each do |d| message << "data: #{d}\n" end message << "\n" end end end end
Version data entries
10 entries across 10 versions & 1 rubygems