Class: Moleculer::Packets::Event

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

Overview

Represents a EVENT 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 = {}) ⇒ Event

Returns a new instance of Event.



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

def initialize(config, data = {})
  super(config, data)

  @event     = HashUtil.fetch(data, :event)
  @data      = HashUtil.fetch(data, :data)
  @broadcast = HashUtil.fetch(data, :broadcast)
  @groups    = HashUtil.fetch(data, :groups, [])
  @node      = HashUtil.fetch(data, :node, nil)
end

Instance Attribute Details

#broadcastObject (readonly)

Returns the value of attribute broadcast.



10
11
12
# File 'lib/moleculer/packets/event.rb', line 10

def broadcast
  @broadcast
end

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/moleculer/packets/event.rb', line 10

def data
  @data
end

#eventObject (readonly)

Returns the value of attribute event.



10
11
12
# File 'lib/moleculer/packets/event.rb', line 10

def event
  @event
end

#groupsObject (readonly)

Returns the value of attribute groups.



10
11
12
# File 'lib/moleculer/packets/event.rb', line 10

def groups
  @groups
end

Instance Method Details

#to_hObject



25
26
27
28
29
30
31
32
# File 'lib/moleculer/packets/event.rb', line 25

def to_h
  super.merge(
    event:     @event,
    data:      @data,
    broadcast: @broadcast,
    groups:    @groups,
  )
end

#topicObject



34
35
36
# File 'lib/moleculer/packets/event.rb', line 34

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