Class: Moleculer::Packets::Info

Inherits:
Base
  • Object
show all
Includes:
Support
Defined in:
lib/moleculer/packets/info.rb

Overview

Represents an INFO packet

Defined Under Namespace

Classes: Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(config, data = {}) ⇒ Info

Returns a new instance of Info.

Parameters:

  • data (Hash) (defaults to: {})

    the packet data



67
68
69
70
71
72
73
74
75
# File 'lib/moleculer/packets/info.rb', line 67

def initialize(config, data = {})
  super(config, data)
  @services = HashUtil.fetch(data, :services)
  @ip_list  = HashUtil.fetch(data, :ip_list)
  @hostname = HashUtil.fetch(data, :hostname)
  @client   = Client.new(HashUtil.fetch(data, :client, {}))
  node      = HashUtil.fetch(data, :node, nil)
  @node_id  = HashUtil.fetch(data, :node_id, node&.id)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



54
55
56
57
58
# File 'lib/moleculer/packets/info.rb', line 54

attr_reader :services,
:config,
:ip_list,
:hostname,
:client

#configMoleculer::Support::OpenStruct (readonly)

Returns the configuration of the node.

Returns:



54
55
56
57
58
# File 'lib/moleculer/packets/info.rb', line 54

attr_reader :services,
:config,
:ip_list,
:hostname,
:client

#hostnameString (readonly)

Returns the hostname of the node.

Returns:

  • (String)

    the hostname of the node



54
55
56
57
58
# File 'lib/moleculer/packets/info.rb', line 54

attr_reader :services,
:config,
:ip_list,
:hostname,
:client

#ip_listArray<String> (readonly)

Returns a list of the node's used IP addresses.

Returns:

  • (Array<String>)

    a list of the node's used IP addresses



54
55
56
57
58
# File 'lib/moleculer/packets/info.rb', line 54

attr_reader :services,
:config,
:ip_list,
:hostname,
:client

#servicesArray<Moleculer::Services::Remote|Moleculer::Services::Base> (readonly)

Returns an array of the services the endpoint provides.

Returns:

  • (Array<Moleculer::Services::Remote|Moleculer::Services::Base>)

    an array of the services the endpoint provides



54
55
56
# File 'lib/moleculer/packets/info.rb', line 54

def services
  @services
end

Instance Method Details

#to_hObject



83
84
85
86
87
88
89
90
91
# File 'lib/moleculer/packets/info.rb', line 83

def to_h
  super.merge(
    services: @services,
    config:   config_for_hash,
    ipList:   @ip_list,
    hostname: @hostname,
    client:   @client.to_h,
  )
end

#topicObject



77
78
79
80
81
# File 'lib/moleculer/packets/info.rb', line 77

def topic
  return "#{super}.#{@node_id}" if @node_id

  super
end