Class: Pantry::MultiCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/pantry/multi_command.rb

Overview

A MultiCommand allows specifying multiple Commands to be run in succession. Each command class given in .performs will have it’s #perform executed and the return values will be grouped together in a single return Message.

It’s currently expected that each Command executed is done when it’s #perform returns.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

This class inherits a constructor from Pantry::Command

Class Method Details

.command_classesObject



16
17
18
# File 'lib/pantry/multi_command.rb', line 16

def self.command_classes
  @command_classes
end

.performs(command_classes = []) ⇒ Object

MultiCommand.performs takes a list of Command class constants.



12
13
14
# File 'lib/pantry/multi_command.rb', line 12

def self.performs(command_classes = [])
  @command_classes = command_classes
end

Instance Method Details

#perform(message) ⇒ Object

Iterate through each Command class and run that Command with the given message. The results of each Command will be combined into a single array return value and thus a single response Message back to the requester.



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

def perform(message)
  Pantry.logger.debug("[#{client.identity}] Running MultiCommands")

  self.class.command_classes.map do |command_class|
    Pantry.logger.debug("[#{client.identity}] Running #{command_class}")
    command = command_class.new
    command.server_or_client = server_or_client
    command.perform(message)
  end
end