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.
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
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 |
#commands ⇒ Array<String>
Return the sorted list of commands supported by this handler
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.
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.
28 29 30 31 |
# File 'lib/ftpd/command_handlers.rb', line 28 def has?(command) command = canonical_command(command) @commands.has_key?(command) end |