Class: Ftpd::CommandHandlers

Inherits:
Object
  • Object
show all
Defined in:
lib/ftpd/command_handlers.rb

Overview

All FTP commands which the server supports are dispatched by this class.

Instance Method Summary collapse

Constructor Details

#initializeCommandHandlers

Returns a new instance of CommandHandlers.



10
11
12
# File 'lib/ftpd/command_handlers.rb', line 10

def initialize
  @commands = {}
end

Instance Method Details

#<<(command_handler) ⇒ Object

Add a command handler

Parameters:

  • command_handler (Command)


18
19
20
21
22
# File 'lib/ftpd/command_handlers.rb', line 18

def <<(command_handler)
  command_handler.commands.each do |command|
    @commands[command] = command_handler
  end
end

#commandsArray<String>

Return the sorted list of commands supported by this handler

Returns:

  • (Array<String>)

    Lowercase command



50
51
52
# File 'lib/ftpd/command_handlers.rb', line 50

def commands
  @commands.keys.sort
end

#execute(command, argument) ⇒ Object

Dispatch a command to the appropriate command handler.

Parameters:

  • command (String)

    the command (e.g. “STOR”). Case insensitive.

  • argument (String)

    The argument, or nil if there isn’t one.



40
41
42
43
44
# File 'lib/ftpd/command_handlers.rb', line 40

def execute(command, argument)
  command = canonical_command(command)
  method = "cmd_#{command}"
  @commands[command.downcase].send(method, argument)
end

#has?(command) ⇒ Boolean

Returns truthy if the server supports the command.

Parameters:

  • command (String)

    the command (e.g. “STOR”). Case insensitive.

Returns:

  • (Boolean)

    truthy if the server supports the command.



28
29
30
31
# File 'lib/ftpd/command_handlers.rb', line 28

def has?(command)
  command = canonical_command(command)
  @commands.has_key?(command)
end