Class: NeocitiesRed::Services::File::FolderUploader
- Inherits:
-
Object
- Object
- NeocitiesRed::Services::File::FolderUploader
- Defined in:
- lib/neocities_red/services/file/folder_uploader.rb
Overview
Uploads all files in a local directory to the remote site in parallel.
Uses a Common::WorkerPool to upload files concurrently up to MAX_THREADS threads. Each file is uploaded via Uploader.
Instance Method Summary collapse
-
#files ⇒ Array<String>?
Recursively lists all files in the local directory.
-
#initialize(client, filepath, remote_path, display: NeocitiesRed::CliDisplay.new) ⇒ FolderUploader
constructor
A new instance of FolderUploader.
-
#upload(files_list, threads = MAX_THREADS) ⇒ void
Uploads all files in the list concurrently.
Constructor Details
#initialize(client, filepath, remote_path, display: NeocitiesRed::CliDisplay.new) ⇒ FolderUploader
Returns a new instance of FolderUploader.
31 32 33 34 35 36 |
# File 'lib/neocities_red/services/file/folder_uploader.rb', line 31 def initialize(client, filepath, remote_path, display: NeocitiesRed::CliDisplay.new) @client = client @filepath = filepath @remote_path = remote_path @display = display end |
Instance Method Details
#files ⇒ Array<String>?
Recursively lists all files in the local directory.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/neocities_red/services/file/folder_uploader.rb', line 43 def files path = Pathname.new(::File.(@filepath)) raise NeocitiesRed::FileNotFoundError, "#{path} does not exist locally." unless path.exist? if path.file? @display.display_skip_file(path) return end Dir.chdir(path) do Dir.glob("**/*", ::File::FNM_DOTMATCH) .select { |f| ::File.file?(f) } end end |
#upload(files_list, threads = MAX_THREADS) ⇒ void
This method returns an undefined value.
Uploads all files in the list concurrently.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/neocities_red/services/file/folder_uploader.rb', line 64 def upload(files_list, threads = MAX_THREADS) base = ::File.(@filepath) worker_pool = Services::Common::WorkerPool.new(threads) do |file| local_path = ::File.join(base, file) remote_path = ::File.join(@remote_path, file) Uploader.new(@client, local_path, remote_path, display: @display).upload end worker_pool.process(files_list) end |