Class: Longleaf::StoragePathValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/longleaf/services/storage_path_validator.rb

Overview

Validator for storage paths

Class Method Summary collapse

Class Method Details

.validate(path) ⇒ Object

Checks that the given path is a syntactically valid storage path

Parameters:

  • path (String)

    file storage path to validate

Raises:



9
10
11
12
13
14
# File 'lib/longleaf/services/storage_path_validator.rb', line 9

def self.validate(path)
  raise InvalidStoragePathError.new("Path must not be empty") if path.to_s.strip.empty?
  raise InvalidStoragePathError.new("Path must be absolute") unless Pathname.new(path).absolute?
  raise InvalidStoragePathError.new("Path must not contain any relative modifiers (/..)") \
      if path.include?('/..')
end