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

Instance Method Details

#clear_downloadsObject



41
42
43
# File 'lib/so_many_devices/downloads_helper.rb', line 41

def clear_downloads
  FileUtils.rm_f(downloads)
end

#downloadObject



10
11
12
# File 'lib/so_many_devices/downloads_helper.rb', line 10

def download
  downloads.first
end

#download_contentObject



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

Returns:

  • (Boolean)


33
34
35
# File 'lib/so_many_devices/downloads_helper.rb', line 33

def downloaded?
  !downloading? && downloads.any?
end

#downloading?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/so_many_devices/downloads_helper.rb', line 37

def downloading?
  downloads.grep(/\.crdownload$/).any?
end

#downloadsObject



6
7
8
# File 'lib/so_many_devices/downloads_helper.rb', line 6

def downloads
  Dir["#{PATH}/*"]
end

#first_downloadObject



14
15
16
# File 'lib/so_many_devices/downloads_helper.rb', line 14

def first_download
  downloads.first
end

#last_downloadObject



18
19
20
# File 'lib/so_many_devices/downloads_helper.rb', line 18

def last_download
  downloads.last
end

#wait_for_downloadObject



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