lib/deepstream/message.rb in deepstream-0.3.2 vs lib/deepstream/message.rb in deepstream-1.0.0

- old
+ new

@@ -7,21 +7,27 @@ def self.parse(*args) args.first.is_a?(self) ? args.first : new(*args) end - def initialize(*args, timeout: nil) + def initialize(*args) if args.one? args = args.first.delete(MESSAGE_SEPARATOR).split(MESSAGE_PART_SEPARATOR) end - @sending_deadline = Time.now + timeout if timeout + @sending_deadline = nil @topic, @action = args.take(2).map(&:to_sym) @data = args.drop(2) + rescue + '' end + def set_timeout(timeout) + @sending_deadline = Time.now + timeout + end + def to_s args = [@topic, @action] - args << @data unless @data.empty? + args << @data unless (@data.nil? || @data.empty?) args.join(MESSAGE_PART_SEPARATOR).concat(MESSAGE_SEPARATOR) end def inspect "#{self.class.name}: #{@topic} #{@action} #{@data}"