Module: ProcessSettings::ReplaceVersionedFile

Defined in:
lib/process_settings/replace_versioned_file.rb

Overview

This class will override a file with a higher version file; it accounts for minor version number use

Defined Under Namespace

Classes: FileDoesNotExistError, SourceVersionOlderError

Class Method Summary collapse

Class Method Details

.replace_file_on_newer_file_version(source_file_path, destination_file_path) ⇒ Object

Contracts

source_file_path must be present
destination_file_path must be present
source_file_path must exist on filesystem
source file version cannot be older destination version


17
18
19
20
21
22
23
24
25
26
# File 'lib/process_settings/replace_versioned_file.rb', line 17

def replace_file_on_newer_file_version(source_file_path, destination_file_path)
  source_file_path.to_s      == '' and raise ArgumentError, "source_file_path not present"
  destination_file_path.to_s == '' and raise ArgumentError, "destination_file_path not present"
  File.exist?(source_file_path) or raise FileDoesNotExistError, "source file '#{source_file_path}' does not exist"
  validate_source_version_is_not_older(source_file_path, destination_file_path)

  if source_version_is_newer?(source_file_path, destination_file_path)
    FileUtils.cp(source_file_path, destination_file_path)
  end
end