class Pubsubstub::Event
Attributes
data[R]
id[R]
name[R]
retry_after[R]
Public Class Methods
from_json(json)
click to toggle source
# File lib/pubsubstub/event.rb, line 20 def self.from_json(json) hash = JSON.load(json) new(hash['data'], name: hash['name'], id: hash['id'], retry_after: hash['retry_after']) end
new(data, options = {})
click to toggle source
# File lib/pubsubstub/event.rb, line 5 def initialize(data, options = {}) @id = options[:id] || time_now @name = options[:name] @retry_after = options[:retry_after] @data = data end
Public Instance Methods
==(other)
click to toggle source
# File lib/pubsubstub/event.rb, line 25 def ==(other) id == other.id && name == other.name && data == other.data && retry_after == other.retry_after end
to_json()
click to toggle source
# File lib/pubsubstub/event.rb, line 12 def to_json {id: @id, name: @name, data: @data, retry_after: @retry_after}.to_json end
to_message()
click to toggle source
# File lib/pubsubstub/event.rb, line 16 def to_message @message ||= build_message end
Private Instance Methods
build_message()
click to toggle source
# File lib/pubsubstub/event.rb, line 31 def build_message data = @data.lines.map{ |segment| "data: #{segment}" }.join message = "id: #{id}\n" message << "event: #{name}\n" if name message << "retry: #{retry_after}\n" if retry_after message << data << "\n\n" message end
time_now()
click to toggle source
# File lib/pubsubstub/event.rb, line 40 def time_now (Time.now.to_f * 1000).to_i end