Sha256: d00e0c3f090932002e10668326a78d45ad4be33d41aceca6d22797ee1e95b638

Contents?: true

Size: 1.7 KB

Versions: 91

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/ukrdc"

module Renalware
  module UKRDC
    class Paths
      attr_reader :timestamp, :batch_number, :working_path

      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

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

      # Name for the symlink to the latest archive folder
      def latest_archive_symlink_name
        @latest_archive_symlink_name ||= archive_folder.join("latest")
      end

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

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

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

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

      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

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

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
renalware-core-2.0.89 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.88 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.87 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.86 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.85 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.84 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.83 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.82 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.81 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.80 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.79 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.78 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.77 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.76 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.75 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.74 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.73 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.72 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.71 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.70 app/models/renalware/ukrdc/paths.rb