class Gorsse::Event

Public Class Methods

new(protocol, target, entity) click to toggle source
# File lib/gorsse/event.rb, line 5
def initialize(protocol, target, entity)
  @protocol = protocol
  @target = target
  @entity = entity
end

Public Instance Methods

send!() click to toggle source
# File lib/gorsse/event.rb, line 11
def send!
  json = JSON.generate(msg)
  Gorsse.conn.send(json)
end

Private Instance Methods

msg() click to toggle source
# File lib/gorsse/event.rb, line 18
def msg
  hash = {
    'proto' => sse_class_for(@protocol),
    'scope' => @protocol.scope,
    'client' => @target.kind_of?(Client) ? @target.uid : 'all',
  }

  if @entity.respond_to?(:to_sse)
    hash['title'] = sse_class_for(@entity)
    hash['content'] = @entity.to_sse
  else
    hash['title'] = @entity.to_s
    hash['content'] = ''
  end

  hash
end
sse_class_for(instance) click to toggle source
# File lib/gorsse/event.rb, line 36
def sse_class_for(instance)
  klass = instance.class
  klass.respond_to?(:sse_name) ? klass.sse_name : klass.name
end