Class: Moleculer::Packets::Res

Inherits:
Base
  • Object
show all
Defined in:
lib/moleculer/packets/res.rb

Overview

Represents a RES packet

Instance Attribute Summary collapse

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

inherited, packet_accessors, packet_attr, packet_name, #sender, #ver

Constructor Details

#initialize(config, data) ⇒ Res

Returns a new instance of Res.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/moleculer/packets/res.rb', line 15

def initialize(config, data)
  super(config, data)

  @id      = HashUtil.fetch(data, :id)
  @success = HashUtil.fetch(data, :success)
  @data    = HashUtil.fetch(data, :data)
  @error   = HashUtil.fetch(data, :error, nil)
  @meta    = HashUtil.fetch(data, :meta)
  @stream  = HashUtil.fetch(data, :stream, false)
  @node    = HashUtil.fetch(data, :node, nil)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/moleculer/packets/res.rb', line 8

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/moleculer/packets/res.rb', line 8

def error
  @error
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/moleculer/packets/res.rb', line 8

def id
  @id
end

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'lib/moleculer/packets/res.rb', line 8

def meta
  @meta
end

#streamObject (readonly)

Returns the value of attribute stream.



8
9
10
# File 'lib/moleculer/packets/res.rb', line 8

def stream
  @stream
end

#successObject (readonly)

Returns the value of attribute success.



8
9
10
# File 'lib/moleculer/packets/res.rb', line 8

def success
  @success
end

Instance Method Details

#to_hObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/moleculer/packets/res.rb', line 31

def to_h
  super.merge(
    id:      @id,
    success: @success,
    data:    @data,
    error:   @error,
    meta:    @meta,
    stream:  @stream,
  )
end

#topicObject



27
28
29
# File 'lib/moleculer/packets/res.rb', line 27

def topic
  "#{super}.#{@node.id}"
end