class FilePipeline::Versions::Validator

Validator objects verify the version file and results returned by a FileOperation.

They will validate:

Attributes

file[R]

File for the version that resulted from a FileOperation.

info[R]

FileOperation::Results object.

Public Class Methods

[](version_info, versioned_file) click to toggle source

Validates file, directory, and info for version_info in the context of versioned_file.

Arguments
  • version_info - path to an existing file or an array with the path and optionally a FileOperations::Results instance.

  • versioned_file - an object that responds to original and

returns a file path, and directory and returns a directory path.

# File lib/file_pipeline/versions/validator.rb, line 46
def self.[](version_info, versioned_file)
  new(version_info, versioned_file.directory, versioned_file.original)
    .validate_info
    .validate_file
    .validate_directory
    .then { |validator| [validator.file, validator.info] }
end
new(version_info, directory, filename) click to toggle source

Returns a new instance.

Arguments
  • version_info - path to an existing file or an array with the path and optionally a FileOperations::Results instance.

  • directory - directory where the file is expected (the working directory of a VersionedFile).

  • filename - name of the file to be returned if the file operation was was non-modifying (usually the VersionedFile#original).

# File lib/file_pipeline/versions/validator.rb, line 31
def initialize(version_info, directory, filename)
  @file, @info = [version_info].flatten
  @directory = directory
  @filename = filename
end

Public Instance Methods

unmodified?() click to toggle source

Returns true when there is no file for the version (result of a non-modifying file operation), false otherwise.

# File lib/file_pipeline/versions/validator.rb, line 56
def unmodified?
  @file.nil?
end
validate_directory() click to toggle source

Raises MisplacedVersionFileError if file is not in directory.

# File lib/file_pipeline/versions/validator.rb, line 61
def validate_directory
  return self if unmodified? || File.dirname(@file) == @directory

  raise Errors::MisplacedVersionFileError.new file: @file,
                                              directory: @directory
end
validate_file() click to toggle source

Raises MissingVersionFileError if file does not exist on the file system.

# File lib/file_pipeline/versions/validator.rb, line 70
def validate_file
  return self if unmodified? || File.exist?(@file)

  raise Errors::MissingVersionFileError.new file: @file
end
validate_info() click to toggle source

Raises FailedModificationError if the file operation generatint the info failed.

# File lib/file_pipeline/versions/validator.rb, line 78
def validate_info
  return self unless @info&.failure

  raise Errors::FailedModificationError.new info: @info, file: @filename
end