class Deepstream::Message

Attributes

action[R]
data[R]
sending_deadline[R]
topic[R]

Public Class Methods

new(*args) click to toggle source
# File lib/deepstream/message.rb, line 12
def initialize(*args)
  if args.one?
    args = args.first.delete(MESSAGE_SEPARATOR).split(MESSAGE_PART_SEPARATOR)
  end
  @sending_deadline = nil
  @topic, @action = args.take(2).map(&:to_sym)
  @data = args.drop(2)
rescue
  ''
end
parse(*args) click to toggle source
# File lib/deepstream/message.rb, line 8
def self.parse(*args)
  args.first.is_a?(self) ? args.first : new(*args)
end

Public Instance Methods

expired?() click to toggle source
# File lib/deepstream/message.rb, line 41
def expired?
  @sending_deadline && @sending_deadline < Time.now
end
inspect() click to toggle source
# File lib/deepstream/message.rb, line 33
def inspect
  "#{self.class.name}: #{@topic} #{@action} #{@data}"
end
needs_authentication?() click to toggle source
# File lib/deepstream/message.rb, line 37
def needs_authentication?
  ![TOPIC::CONNECTION, TOPIC::AUTH].include?(@topic)
end
set_timeout(timeout) click to toggle source
# File lib/deepstream/message.rb, line 23
def set_timeout(timeout)
  @sending_deadline = Time.now + timeout
end
to_s() click to toggle source
# File lib/deepstream/message.rb, line 27
def to_s
  args = [@topic, @action]
  args << @data unless (@data.nil? || @data.empty?)
  args.join(MESSAGE_PART_SEPARATOR).concat(MESSAGE_SEPARATOR)
end