Class: Ftpd::CommandHandlers
- Inherits:
-
Object
- Object
- Ftpd::CommandHandlers
- Defined in:
- lib/ftpd/command_handlers.rb
Overview
All FTP commands which the server supports are dispatched by this class.
Instance Method Summary collapse
-
#<<(command_handler) ⇒ Object
Add a command handler.
-
#commands ⇒ Array<String>
Return the sorted list of commands supported by this handler.
-
#execute(command, argument) ⇒ Object
Dispatch a command to the appropriate command handler.
-
#has?(command) ⇒ Boolean
Truthy if the server supports the command.
-
#initialize ⇒ CommandHandlers
constructor
A new instance of CommandHandlers.
Constructor Details
#initialize ⇒ CommandHandlers
Returns a new instance of CommandHandlers.
8 9 10 |
# File 'lib/ftpd/command_handlers.rb', line 8 def initialize @commands = {} end |
Instance Method Details
#<<(command_handler) ⇒ Object
Add a command handler
16 17 18 19 20 |
# File 'lib/ftpd/command_handlers.rb', line 16 def <<(command_handler) command_handler.commands.each do |command| @commands[command] = command_handler end end |
#commands ⇒ Array<String>
Return the sorted list of commands supported by this handler
48 49 50 |
# File 'lib/ftpd/command_handlers.rb', line 48 def commands @commands.keys.sort end |
#execute(command, argument) ⇒ Object
Dispatch a command to the appropriate command handler.
38 39 40 41 42 |
# File 'lib/ftpd/command_handlers.rb', line 38 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.
26 27 28 29 |
# File 'lib/ftpd/command_handlers.rb', line 26 def has?(command) command = canonical_command(command) @commands.has_key?(command) end |