Method: PortalModule::LoanEntry#download

Defined in:
lib/portal_module/loan_entry.rb

#download(org, file_path) ⇒ Object

Export loan entry data for an org unit to a file



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/portal_module/loan_entry.rb', line 38

def download org, file_path
  assert_org_is_configured org
  assert_dl_dir_is_configured
  assert_dir_exists file_path

  loan_entry_page
    .load_org(org_string(org))
    .download

  file_path = Pathname(file_path)
  file_path = file_path + DL_FILENAME if file_path.directory?

  dl_file = download_dir + DL_FILENAME
  wait_for_file(dl_file, PortalModule.configuration.download_timeout)
  assert_file_exists dl_file

  FileUtils.mv dl_file, file_path

rescue Exception => e
  if e.message.include? 'No such file or directory'
    raise IOError, "No such directory - #{file_path}"
  else
    raise e
  end
end