class Ellipses::Support::SanitizePath::Sanitizer

Constants

MissingBase
MissingPath
NotDir
NotExecutable
NotFile
WrongBase

Attributes

base[R]
fullpath[R]
path[R]

Public Class Methods

new(path:, base: nil) click to toggle source
# File lib/ellipses/support/sanitize_path.rb, line 32
def initialize(path:, base: nil)
  @path     = ::File.join(*path)
  @base     = ::File.join(*base) if base
  @fullpath = ::File.expand_path(@path, @base)
end
sanitize(*args, **kwargs) click to toggle source
# File lib/ellipses/support/sanitize_path.rb, line 7
def self.sanitize(*args, **kwargs)
  new(*args, **kwargs).sanitize
end

Public Instance Methods

sanitize() click to toggle source
# File lib/ellipses/support/sanitize_path.rb, line 38
def sanitize
  if base
    raise MissingBase, base unless ::File.exist?(base)
    raise WrongBase,   base unless ::File.directory?(base)
  end

  raise MissingPath, fullpath unless ::File.exist?(fullpath)

  call

  fullpath
end