Class: Wamp::Worker::Queue::Descriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/wamp/worker/queue.rb

Overview

This class represents the payload that will be stored in Redis

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, handle, params) ⇒ Descriptor

Constructor

Parameters:

  • command (Symbol)
    • The command for the descriptor

  • handle (String)
    • The handle representing the descriptor

  • params (Hash)
    • The params for the command



18
19
20
21
22
# File 'lib/wamp/worker/queue.rb', line 18

def initialize(command, handle, params)
  @command = command.to_sym
  @handle = handle
  @params = params || {}
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



11
12
13
# File 'lib/wamp/worker/queue.rb', line 11

def command
  @command
end

#handleObject (readonly)

Returns the value of attribute handle.



11
12
13
# File 'lib/wamp/worker/queue.rb', line 11

def handle
  @handle
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/wamp/worker/queue.rb', line 11

def params
  @params
end

Class Method Details

.from_json(json_string) ⇒ Descriptor

Create a Descriptor object from the json payload

Parameters:

  • json_string (String)
    • The string from the Redis store

Returns:



28
29
30
31
32
# File 'lib/wamp/worker/queue.rb', line 28

def self.from_json(json_string)
  return unless json_string
  parsed = JSON.parse(json_string, :symbolize_names => true)
  self.new(parsed[:command], parsed[:handle], parsed[:params])
end

Instance Method Details

#to_jsonString

Creates the json payload from the object

Returns:

  • (String)
    • The string that will go into the Redis store



37
38
39
# File 'lib/wamp/worker/queue.rb', line 37

def to_json
  { command: self.command, handle: self.handle, params: self.params }.to_json
end