Module: SoManyDevices::DownloadsHelper
- Defined in:
- lib/so_many_devices/downloads_helper.rb
Constant Summary collapse
- TIMEOUT =
10
- PATH =
"#{Dir.pwd}/tmp/downloads"
Instance Method Summary collapse
- #clear_downloads ⇒ Object
- #download ⇒ Object
- #download_content ⇒ Object
- #downloaded? ⇒ Boolean
- #downloading? ⇒ Boolean
- #downloads ⇒ Object
- #first_download ⇒ Object
- #last_download ⇒ Object
- #wait_for_download ⇒ Object
Instance Method Details
#clear_downloads ⇒ Object
41 42 43 |
# File 'lib/so_many_devices/downloads_helper.rb', line 41 def clear_downloads FileUtils.rm_f(downloads) end |
#download ⇒ Object
10 11 12 |
# File 'lib/so_many_devices/downloads_helper.rb', line 10 def download downloads.first end |
#download_content ⇒ Object
22 23 24 25 |
# File 'lib/so_many_devices/downloads_helper.rb', line 22 def download_content wait_for_download File.read(download) end |
#downloaded? ⇒ Boolean
33 34 35 |
# File 'lib/so_many_devices/downloads_helper.rb', line 33 def downloaded? !downloading? && downloads.any? end |
#downloading? ⇒ Boolean
37 38 39 |
# File 'lib/so_many_devices/downloads_helper.rb', line 37 def downloading? downloads.grep(/\.crdownload$/).any? end |
#downloads ⇒ Object
6 7 8 |
# File 'lib/so_many_devices/downloads_helper.rb', line 6 def downloads Dir["#{PATH}/*"] end |
#first_download ⇒ Object
14 15 16 |
# File 'lib/so_many_devices/downloads_helper.rb', line 14 def first_download downloads.first end |
#last_download ⇒ Object
18 19 20 |
# File 'lib/so_many_devices/downloads_helper.rb', line 18 def last_download downloads.last end |
#wait_for_download ⇒ Object
27 28 29 30 31 |
# File 'lib/so_many_devices/downloads_helper.rb', line 27 def wait_for_download Timeout.timeout(TIMEOUT) do sleep 0.1 until downloaded? end end |