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, timeout: nil) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ Object
- #needs_authentication? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(*args, timeout: nil) ⇒ Message
Returns a new instance of Message.
12 13 14 15 16 17 18 19 |
# File 'lib/deepstream/message.rb', line 12 def initialize(*args, timeout: nil) if args.one? args = args.first.delete(MESSAGE_SEPARATOR).split(MESSAGE_PART_SEPARATOR) end @sending_deadline = Time.now + timeout if timeout @topic, @action = args.take(2).map(&:to_sym) @data = args.drop(2) 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
35 36 37 |
# File 'lib/deepstream/message.rb', line 35 def expired? @sending_deadline && @sending_deadline < Time.now end |
#inspect ⇒ Object
27 28 29 |
# File 'lib/deepstream/message.rb', line 27 def inspect "#{self.class.name}: #{@topic} #{@action} #{@data}" end |
#needs_authentication? ⇒ Boolean
31 32 33 |
# File 'lib/deepstream/message.rb', line 31 def needs_authentication? ![TOPIC::CONNECTION, TOPIC::AUTH].include?(@topic) end |
#to_s ⇒ Object
21 22 23 24 25 |
# File 'lib/deepstream/message.rb', line 21 def to_s args = [@topic, @action] args << @data unless @data.empty? args.join(MESSAGE_PART_SEPARATOR).concat(MESSAGE_SEPARATOR) end |