class Pantry::MultiCommand

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.

Public Class Methods

command_classes() click to toggle source
# File lib/pantry/multi_command.rb, line 16
def self.command_classes
  @command_classes
end
performs(command_classes = []) click to toggle source

MultiCommand.performs takes a list of Command class constants.

# File lib/pantry/multi_command.rb, line 12
def self.performs(command_classes = [])
  @command_classes = command_classes
end

Public Instance Methods

perform(message) click to toggle source

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.

# 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