class Novika::Resolver::Disk

Overview

A caching, resolver-specific file system access abstraction on top of Crystal's Dir and File.

Defined in:

novika/resolver.cr

Constant Summary

InfoAbsent = InfoAbsence.new

Singleton instance of InfoAbsence.

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Instance Method Detail

def dir?(path : Path) : Path | Nil #

If path (symlink or not) points to a directory, returns the real path to that directory. Otherwise, returns nil.


def env?(origin : Path) : Path | Nil #

Determines and returns the path to the environment directory, if any. Otherwise, returns nil.

Climbs up from origin until encountering:

  • A file named '.nk.env'
  • A directory named 'env' containing a file named '.nk.env'
  • A directory named '.novika'

The result is cached, recursively, so you can call this method as many times as you'd like; your disk won't explode.


def file?(path : Path) : Path | Nil #

If path (symlink or not) points to a file, returns the real path to that file. Otherwise, returns nil.


def glob(origin : Path, selector : GlobSelector, &fn : Path -> ) #

A simpler, Novika- and Disk-specific globbing mechanism.

Calls fn with paths in origin directory that match the given selector.


def info?(path : Path) : InfoPresence | Nil #

Reads, caches, and returns the InfoPresence object for the given path. Returns nil if there is nothing at path. The absence is also cached.

path is assumed to be absolute and normalized.

If path is a symlink, the symlink is visited. Therefore, the returned InfoPresence will contain the real path rather than path. So prefer to use the resulting InfoPresence#path in favor of path after calling this method.


def read(path : Path) : String | Nil #

Returns the content of the file that path points to.

Raises if path doesn't point to a file.


def write(path : Path, & : IO -> ) #

Yields writable IO for the file that path points to. The file is created if it does not exist; its content is cleared if it does.