Class: Pantry::Commands::Status

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Pantry::Command

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

Constructor Details

This class inherits a constructor from Pantry::Command

Instance Attribute Details

#client_filterObject

Returns the value of attribute client_filter.



10
11
12
# File 'lib/pantry/commands/status.rb', line 10

def client_filter
  @client_filter
end

Instance Method Details

#perform(message) ⇒ Object

Return information about all connected Clients that match the given filter



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pantry/commands/status.rb', line 28

def perform(message)
  @client_filter = Pantry::Communication::ClientFilter.new(**(message.body[0] || {}))
  self.server.client_registry.all_matching(@client_filter) do |client, record|
    {
      identity:        client.identity,
      application:     client.application,
      environment:     client.environment,
      roles:           client.roles,
      last_checked_in: record.last_checked_in_at
    }
  end
end

#prepare_message(options) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/pantry/commands/status.rb', line 12

def prepare_message(options)
  @client_filter = Pantry::Communication::ClientFilter.new(
    application: options[:application],
    environment: options[:environment],
    roles: options[:roles]
  )
  super
end

#receive_server_response(message) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pantry/commands/status.rb', line 41

def receive_server_response(message)
  output =
    clients = message.body.map do |client|
      [
        time_ago_in_words(client[:last_checked_in]),
        client[:identity],
        "|",
        client[:application],
        client[:environment],
        [client[:roles]].flatten.join(",")
      ].compact.join(" ")
    end

  Pantry.ui.list(output)
end

#to_messageObject



21
22
23
24
25
# File 'lib/pantry/commands/status.rb', line 21

def to_message
  message = super
  message << @client_filter.to_hash
  message
end