class Pantry::Commands::DownloadDirectory

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.

Public Class Methods

new(directory = nil) click to toggle source
# File lib/pantry/commands/download_directory.rb, line 12
def initialize(directory = nil)
  @directory = directory
end

Public Instance Methods

perform(message) click to toggle source
# File lib/pantry/commands/download_directory.rb, line 22
def perform(message)
  directory = Pantry.root.join(message.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() click to toggle source
Calls superclass method Pantry::Command#to_message
# File lib/pantry/commands/download_directory.rb, line 16
def to_message
  super.tap do |message|
    message << @directory.to_s
  end
end