Image.Plug.VariantStore behaviour (image_plug v0.1.0)

Copy Markdown View Source

Behaviour for variant stores.

A variant store persists Image.Plug.Variant records keyed by name. Reads are expected to be cheap (every request that resolves a variant performs one read); writes are expected to be infrequent.

The default implementation Image.Plug.VariantStore.ETS is in-memory. A file-backed and a database-backed store may follow in later milestones.

Summary

Callbacks

Deletes a variant by name.

Fetches a variant by name.

Lists every stored variant. The order is implementation-defined.

Inserts or updates a variant.

Callbacks

delete(name, options)

@callback delete(name :: String.t(), options :: keyword()) :: :ok | {:error, :not_found}

Deletes a variant by name.

Returns :ok or {:error, :not_found}.

get(name, options)

@callback get(name :: String.t(), options :: keyword()) ::
  {:ok, Image.Plug.Variant.t()} | {:error, :not_found}

Fetches a variant by name.

Returns {:ok, variant} or {:error, :not_found}.

list(options)

@callback list(options :: keyword()) :: {:ok, [Image.Plug.Variant.t()]}

Lists every stored variant. The order is implementation-defined.

put(t, options)

@callback put(Image.Plug.Variant.t(), options :: keyword()) ::
  {:ok, Image.Plug.Variant.t()} | {:error, term()}

Inserts or updates a variant.

Returns {:ok, stored} where stored may differ from the input (for example, with :inserted_at / :updated_at populated).