Class: Wamp::Client::Message::Publish

Inherits:
Base
  • Object
show all
Defined in:
lib/wamp/client/message.rb

Overview

Publish Sent by a Publisher to a Broker to publish an event. Formats:

[PUBLISH, Request|id, Options|dict, Topic|uri]
[PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list]
[PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list, ArgumentsKw|dict]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Check

included

Constructor Details

#initialize(request, options, topic, arguments = nil, argumentskw = nil) ⇒ Publish

Returns a new instance of Publish.



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/wamp/client/message.rb', line 308

def initialize(request, options, topic, arguments=nil, argumentskw=nil)

  self.class.check_id('request', request)
  self.class.check_dict('options', options)
  self.class.check_uri('topic', topic)
  self.class.check_list('arguments', arguments, true)
  self.class.check_dict('argumentskw', argumentskw, true)

  self.request = request
  self.options = options
  self.topic = topic
  self.arguments = arguments
  self.argumentskw = argumentskw

end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



306
307
308
# File 'lib/wamp/client/message.rb', line 306

def arguments
  @arguments
end

#argumentskwObject

Returns the value of attribute argumentskw.



306
307
308
# File 'lib/wamp/client/message.rb', line 306

def argumentskw
  @argumentskw
end

#optionsObject

Returns the value of attribute options.



306
307
308
# File 'lib/wamp/client/message.rb', line 306

def options
  @options
end

#requestObject

Returns the value of attribute request.



306
307
308
# File 'lib/wamp/client/message.rb', line 306

def request
  @request
end

#topicObject

Returns the value of attribute topic.



306
307
308
# File 'lib/wamp/client/message.rb', line 306

def topic
  @topic
end

Class Method Details

.parse(params) ⇒ Object



328
329
330
331
332
333
334
335
336
# File 'lib/wamp/client/message.rb', line 328

def self.parse(params)

  self.check_gte('params list', 4, params.count)
  self.check_equal('message type', self.type, params[0])

  params.shift
  self.new(*params)

end

.typeObject



324
325
326
# File 'lib/wamp/client/message.rb', line 324

def self.type
  Types::PUBLISH
end

Instance Method Details

#payloadObject



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/wamp/client/message.rb', line 338

def payload
  self.arguments ||= []
  self.argumentskw ||= {}

  payload = [self.class.type]
  payload.push(self.request)
  payload.push(self.options)
  payload.push(self.topic)

  return payload if (self.arguments.empty? and self.argumentskw.empty?)
  payload.push(self.arguments)

  return payload if (self.argumentskw.empty?)
  payload.push(self.argumentskw)

  payload
end

#to_sObject



356
357
358
# File 'lib/wamp/client/message.rb', line 356

def to_s
  'PUBLISH > ' + self.payload.to_s
end