class PortalModule::Dts

Constants

DL_FILENAME

Attributes

page_factory[R]

Public Class Methods

new(page_factory) click to toggle source
# File lib/portal_module/dts.rb, line 20
def initialize(page_factory)
  @page_factory = page_factory
end

Public Instance Methods

activate() click to toggle source
# File lib/portal_module/dts.rb, line 28
def activate
  dts_page.activate
end
download(org, file_path) click to toggle source
# File lib/portal_module/dts.rb, line 37
def download org, file_path
  assert_org_is_configured org
  assert_dl_dir_is_configured
  assert_dir_exists file_path

  dts_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
save() click to toggle source
# File lib/portal_module/dts.rb, line 24
def save
  dts_page.save
end
set_org(org) click to toggle source
# File lib/portal_module/dts.rb, line 32
def set_org org
  assert_org_is_configured org
  dts_page.load_org(org_string(org))
end
upload(org, file_path) click to toggle source

Import DTS configurations into the current environment from a file.

# File lib/portal_module/dts.rb, line 66
def upload org, file_path
  assert_org_is_configured org
  assert_file_exists file_path

  dts_page
    .load_org(org_string(org))
    .upload(Pathname(file_path).expand_path)
end

Private Instance Methods

download_dir() click to toggle source
# File lib/portal_module/dts.rb, line 81
def download_dir
  Pathname(PortalModule.configuration.download_dir)
end
dts_page() click to toggle source
# File lib/portal_module/dts.rb, line 77
def dts_page
  page_factory.dts_page
end
org_string(org) click to toggle source
# File lib/portal_module/dts.rb, line 85
def org_string org
  orgid = PortalModule.configuration.orgs[org]
  orgstr = "#{orgid}~#{org}"
end
wait_for_file(file_path, timeout_secs) click to toggle source
# File lib/portal_module/dts.rb, line 90
def wait_for_file(file_path, timeout_secs)
  stop_time = Time.now + timeout_secs
  file_path = Pathname(file_path)
  while !file_path.exist?
    break if stop_time <= Time.now
    sleep 1
  end
end