Class: Pantry::Commands::RegisterClient

Inherits:
Pantry::Command show all
Defined in:
lib/pantry/commands/register_client.rb

Instance Method Summary collapse

Methods inherited from Pantry::Command

command, #finished, #finished?, message_type, #prepare_message, #receive_client_response, #receive_response, #receive_server_response, #send_request, #send_request!, #server_or_client, #server_or_client=, #wait_for_finish

Constructor Details

#initialize(client_info = nil) ⇒ RegisterClient

Returns a new instance of RegisterClient.



6
7
8
# File 'lib/pantry/commands/register_client.rb', line 6

def initialize(client_info = nil)
  @client_info = client_info
end

Instance Method Details

#perform(message) ⇒ Object

Take note that a Client has connected and registered itself with this Server.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pantry/commands/register_client.rb', line 22

def perform(message)
  details = message.body[0]

  @client_info = Pantry::ClientInfo.new(
    identity:    message.from,
    application: details[:application],
    environment: details[:environment],
    roles:       details[:roles]
  )

  self.server.register_client(@client_info)
end

#to_messageObject



10
11
12
13
14
15
16
17
18
# File 'lib/pantry/commands/register_client.rb', line 10

def to_message
  message = super
  message << {
    application: @client_info.application,
    environment: @client_info.environment,
    roles:       @client_info.roles
  }
  message
end