Class: Deepstream::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/deepstream/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Message

Returns a new instance of Message.



12
13
14
15
16
17
18
19
20
21
# 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

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/deepstream/message.rb', line 6

def action
  @action
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/deepstream/message.rb', line 6

def data
  @data
end

#sending_deadlineObject (readonly)

Returns the value of attribute sending_deadline.



6
7
8
# File 'lib/deepstream/message.rb', line 6

def sending_deadline
  @sending_deadline
end

#topicObject (readonly)

Returns the value of attribute topic.



6
7
8
# File 'lib/deepstream/message.rb', line 6

def topic
  @topic
end

Class Method Details

.parse(*args) ⇒ Object



8
9
10
# File 'lib/deepstream/message.rb', line 8

def self.parse(*args)
  args.first.is_a?(self) ? args.first : new(*args)
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/deepstream/message.rb', line 41

def expired?
  @sending_deadline && @sending_deadline < Time.now
end

#inspectObject



33
34
35
# File 'lib/deepstream/message.rb', line 33

def inspect
  "#{self.class.name}: #{@topic} #{@action} #{@data}"
end

#needs_authentication?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/deepstream/message.rb', line 37

def needs_authentication?
  ![TOPIC::CONNECTION, TOPIC::AUTH].include?(@topic)
end

#set_timeout(timeout) ⇒ Object



23
24
25
# File 'lib/deepstream/message.rb', line 23

def set_timeout(timeout)
  @sending_deadline = Time.now + timeout
end

#to_sObject



27
28
29
30
31
# 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