AshBackendDrivenOptimisticUi.Snapshot (AshBackendDrivenOptimisticUi v0.1.0)

Copy Markdown View Source

The committed copy of every rule, one pretty-printed JSON file per rule at <dir>/<type>.<action>.json, keys sorted so a diff shows only real changes. AshBackendDrivenOptimisticUi.Test compares against it, mix optimistic_ui.snapshot rewrites it.

Summary

Functions

The snapshot directory: the :snapshot_dir option, else test/optimistic_ui/__snapshots__.

How dir differs from rules: rules without a file, files whose content differs, files without a rule.

The rule keys that have a file in dir, sorted.

The file holding rule key ("<type>.<action>") in dir.

The file content for rule: key-sorted pretty JSON with a trailing newline.

Writes every rule to dir and deletes files with no rule; returns the keys written and removed.

Functions

dir(opts \\ [])

@spec dir(keyword()) :: Path.t()

The snapshot directory: the :snapshot_dir option, else test/optimistic_ui/__snapshots__.

drift(rules, dir)

@spec drift(%{required(String.t()) => term()}, Path.t()) :: %{
  missing: [String.t()],
  changed: [String.t()],
  stale: [String.t()]
}

How dir differs from rules: rules without a file, files whose content differs, files without a rule.

keys_on_disk(dir)

@spec keys_on_disk(Path.t()) :: [String.t()]

The rule keys that have a file in dir, sorted.

path(dir, key)

@spec path(Path.t(), String.t()) :: Path.t()

The file holding rule key ("<type>.<action>") in dir.

render(rule)

@spec render(term()) :: String.t()

The file content for rule: key-sorted pretty JSON with a trailing newline.

write(rules, dir)

@spec write(%{required(String.t()) => term()}, Path.t()) :: %{
  written: [String.t()],
  removed: [String.t()]
}

Writes every rule to dir and deletes files with no rule; returns the keys written and removed.