Class: Pantry::Commands::DownloadDirectory
- Inherits:
-
Pantry::Command
- Object
- Pantry::Command
- Pantry::Commands::DownloadDirectory
- Defined in:
- lib/pantry/commands/download_directory.rb
Overview
Download all content inside of the given directory.
This command expects simple directories with a small number of files that are themselves small in size, as this command reads every file into memory and sends that raw content back to the Client. If there are more substantial files to transfer use #send_file and #receive_file instead.
Instance Method Summary collapse
-
#initialize(directory = nil) ⇒ DownloadDirectory
constructor
A new instance of DownloadDirectory.
- #perform(message) ⇒ Object
- #to_message ⇒ Object
Methods inherited from Pantry::Command
command, #finished, #finished?, message_type, #prepare_message, #receive_client_response, #receive_response, #receive_server_response, #send_request, #send_request!, #server_or_client, #server_or_client=, #wait_for_finish
Constructor Details
#initialize(directory = nil) ⇒ DownloadDirectory
Returns a new instance of DownloadDirectory.
12 13 14 |
# File 'lib/pantry/commands/download_directory.rb', line 12 def initialize(directory = nil) @directory = directory end |
Instance Method Details
#perform(message) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/pantry/commands/download_directory.rb', line 22 def perform() directory = Pantry.root.join(.body[0]) Dir[directory.join("**", "*")].map do |file| next if File.directory?(file) [Pathname.new(file).relative_path_from(directory).to_s, File.read(file)] end.compact end |
#to_message ⇒ Object
16 17 18 19 20 |
# File 'lib/pantry/commands/download_directory.rb', line 16 def super.tap do || << @directory.to_s end end |