class FilePipeline::Versions::Validator
Validator
objects verify the version file and results returned by a FileOperation.
They will validate:
-
that the version file existst
-
that it is in the correct directory
-
that the file operation has not returned any failures
Attributes
File for the version that resulted from a FileOperation.
FileOperation::Results object.
Public Class Methods
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 aFileOperations::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
Returns a new instance.
Arguments¶ ↑
-
version_info
- path to an existing file or an array with the path and optionally aFileOperations::Results
instance. -
directory
- directory where the file is expected (the working directory of aVersionedFile
). -
filename
- name of the file to be returned if the file operation was was non-modifying (usually theVersionedFile#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
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
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
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
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