Sha256: 00ae05476b3a2848ca0d03f08fe610f1edb298b0122bbebdcc3938c4bff996b9

Contents?: true

Size: 717 Bytes

Versions: 11

Compression:

Stored size: 717 Bytes

Contents

##
# This class provides methods for EventSource connection instance.
# @attr [Midori::Connection] connection the connection instance of EventMachine
class Midori::EventSource
  attr_accessor :connection

  # Init a EventSource instance with a connection
  # @param [Midori::Connection] connection the connection instance of EventMachine
  def initialize(connection)
    @connection = connection
  end

  # Send data and close the connection
  # @param [String] data data to be sent
  def send(data)
    raise Midori::Exception::EventSourceTypeError unless data.is_a? String
    @connection.send_data(data.split("\n").map {|str| "data: #{str}\n"}.join + "\n")
    @connection.close_connection_after_writing
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
midori.rb-0.7.0 lib/midori/eventsource.rb
midori.rb-0.6.0 lib/midori/eventsource.rb
midori.rb-0.5.4 lib/midori/eventsource.rb
midori.rb-0.5.3.1 lib/midori/eventsource.rb
midori.rb-0.5.3 lib/midori/eventsource.rb
midori.rb-0.5.2 lib/midori/eventsource.rb
midori.rb-0.5.1 lib/midori/eventsource.rb
midori.rb-0.5.0 lib/midori/eventsource.rb
midori.rb-0.4.4.1 lib/midori/eventsource.rb
midori.rb-0.4.4 lib/midori/eventsource.rb
midori.rb-0.4.3 lib/midori/eventsource.rb