Class: Renalware::UKRDC::Paths

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/ukrdc/paths.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp: nil, batch_number:, working_path:) ⇒ Paths

Returns a new instance of Paths.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
# File 'app/models/renalware/ukrdc/paths.rb', line 10

def initialize(timestamp: nil, batch_number:, working_path:)
  raise(ArgumentError, "Invalid working_path") if working_path.blank?

  @timestamp = timestamp
  @batch_number = batch_number
  @timestamp ||= Time.zone.now.strftime("%Y%m%d%H%M%S%L")
  @working_path = Pathname(working_path)
  create_folders
end

Instance Attribute Details

#batch_numberObject (readonly)

Returns the value of attribute batch_number.



8
9
10
# File 'app/models/renalware/ukrdc/paths.rb', line 8

def batch_number
  @batch_number
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



8
9
10
# File 'app/models/renalware/ukrdc/paths.rb', line 8

def timestamp
  @timestamp
end

#working_pathObject (readonly)

Returns the value of attribute working_path.



8
9
10
# File 'app/models/renalware/ukrdc/paths.rb', line 8

def working_path
  @working_path
end

Instance Method Details

#archive_folderObject



20
21
22
# File 'app/models/renalware/ukrdc/paths.rb', line 20

def archive_folder
  @archive_folder ||= working_path.join("archive")
end

#create_foldersObject



52
53
54
55
56
# File 'app/models/renalware/ukrdc/paths.rb', line 52

def create_folders
  FileUtils.mkdir_p timestamped_xml_folder
  FileUtils.mkdir_p timestamped_encrypted_folder
  FileUtils.mkdir_p outgoing_folder
end


45
46
47
48
49
50
# File 'app/models/renalware/ukrdc/paths.rb', line 45

def create_symlink_to_latest_timestamped_folder_so_it_is_easier_to_eyeball
  if File.exist?(latest_archive_symlink_name)
    FileUtils.rm(latest_archive_symlink_name)
  end
  FileUtils.ln_sf(timestamped_folder, latest_archive_symlink_name)
end

Name for the symlink to the latest archive folder



25
26
27
# File 'app/models/renalware/ukrdc/paths.rb', line 25

def latest_archive_symlink_name
  @latest_archive_symlink_name ||= archive_folder.join("latest")
end

#outgoing_folderObject



29
30
31
# File 'app/models/renalware/ukrdc/paths.rb', line 29

def outgoing_folder
  @outgoing_folder ||= working_path.join("outgoing")
end

#timestamped_encrypted_folderObject



41
42
43
# File 'app/models/renalware/ukrdc/paths.rb', line 41

def timestamped_encrypted_folder
  @timestamped_encrypted_folder ||= timestamped_folder.join("encrypted")
end

#timestamped_folderObject



33
34
35
# File 'app/models/renalware/ukrdc/paths.rb', line 33

def timestamped_folder
  @timestamped_folder ||= archive_folder.join("#{batch_number}_#{timestamp}")
end

#timestamped_xml_folderObject



37
38
39
# File 'app/models/renalware/ukrdc/paths.rb', line 37

def timestamped_xml_folder
  @timestamped_xml_folder ||= timestamped_folder.join("xml")
end