-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module DownloadHelpers | ||
TIMEOUT = 20 | ||
PATH = Rails.root.join('tmp', 'downloads') | ||
TIMEOUT = 20 | ||
PATH = Rails.root.join('tmp', 'downloads') | ||
|
||
def downloads | ||
Dir[PATH.join('*')] | ||
end | ||
def downloads | ||
Dir[PATH.join('*')] | ||
end | ||
|
||
def download | ||
downloads.first | ||
end | ||
def download | ||
downloads.first | ||
end | ||
|
||
def download_content | ||
wait_for_download | ||
File.read(download) | ||
end | ||
def download_content | ||
wait_for_download | ||
File.read(download) | ||
end | ||
|
||
def wait_for_download | ||
Timeout.timeout(TIMEOUT) do | ||
sleep 0.1 until downloaded? | ||
end | ||
def wait_for_download | ||
Timeout.timeout(TIMEOUT) do | ||
sleep 0.1 until downloaded? | ||
end | ||
end | ||
|
||
def downloaded? | ||
!downloading? && downloads.any? | ||
end | ||
def downloaded? | ||
!downloading? && downloads.any? | ||
end | ||
|
||
def downloading? | ||
downloads.grep(/\.crdownload$/).any? | ||
end | ||
def downloading? | ||
downloads.grep(/\.crdownload$/).any? | ||
end | ||
|
||
def clear_downloads | ||
FileUtils.rm_f(downloads) | ||
end | ||
def clear_downloads | ||
FileUtils.rm_f(downloads) | ||
end | ||
end |