Class: Deepstream::Message
- Inherits:
-
Object
- Object
- Deepstream::Message
- Defined in:
- lib/deepstream/message.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#sending_deadline ⇒ Object
readonly
Returns the value of attribute sending_deadline.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(*args) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ Object
- #needs_authentication? ⇒ Boolean
- #set_timeout(timeout) ⇒ Object
- #to_s ⇒ Object
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/deepstream/message.rb', line 6 def action @action end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/deepstream/message.rb', line 6 def data @data end |
#sending_deadline ⇒ Object (readonly)
Returns the value of attribute sending_deadline.
6 7 8 |
# File 'lib/deepstream/message.rb', line 6 def sending_deadline @sending_deadline end |
#topic ⇒ Object (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
41 42 43 |
# File 'lib/deepstream/message.rb', line 41 def expired? @sending_deadline && @sending_deadline < Time.now end |
#inspect ⇒ Object
33 34 35 |
# File 'lib/deepstream/message.rb', line 33 def inspect "#{self.class.name}: #{@topic} #{@action} #{@data}" end |
#needs_authentication? ⇒ 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_s ⇒ Object
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 |