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.153 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.152 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.151 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.149 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.148 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.147 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.146 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.145 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.144 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.143 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.142 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.141 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.140 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.139 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.138 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.137 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.136 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.135 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.134 app/models/renalware/ukrdc/paths.rb
renalware-core-2.0.133 app/models/renalware/ukrdc/paths.rb