Juggernaut.Store (Juggernaut v0.4.0)

Copy Markdown View Source

The files Juggernaut keeps under _build/juggernaut/ (design notes §7).

This is the API the views read from:

Every JSON file carries "format". Whole-file writes go through write_atomic/2 (a temporary file in the same directory, then a rename).

Summary

Functions

Reads and decodes a JSON file (string keys).

The store root of the project at project_root.

Writes contents to path atomically: a temporary file in the same directory, then File.rename/2. Parent directories are created.

Functions

read_json(path)

@spec read_json(Path.t()) :: {:ok, term()} | {:error, String.t()}

Reads and decodes a JSON file (string keys).

root(project_root \\ File.cwd!())

@spec root(Path.t()) :: Path.t()

The store root of the project at project_root.

write_atomic(path, contents, opts \\ [])

@spec write_atomic(Path.t(), iodata(), keyword()) :: :ok | {:error, File.posix()}

Writes contents to path atomically: a temporary file in the same directory, then File.rename/2. Parent directories are created.

With mode: mode the temporary file is created empty and given mode before contents are written to it, so the contents are never readable with wider permissions, at the temporary path or the final one (for secrets such as the server's token).