First pass at uniformed types, specs and docs
- spec public functions (skipping controllers, views, live views and components) - use types instead of explanations in docs - remove redundant docs - fix typos
This commit is contained in:
@@ -8,6 +8,7 @@ defmodule MusicLibrary.Assets do
|
||||
Store any file type - the responsibility to correctly populate format and
|
||||
properties is left to the caller.
|
||||
"""
|
||||
@spec store(map()) :: {:ok, Asset.t()} | {:error, Ecto.Changeset.t()}
|
||||
def store(params) do
|
||||
%Asset{}
|
||||
|> Asset.changeset(params)
|
||||
@@ -17,20 +18,24 @@ defmodule MusicLibrary.Assets do
|
||||
@doc """
|
||||
Store image files - properties will be computed automatically.
|
||||
"""
|
||||
@spec store_image(map()) :: {:ok, Asset.t()} | {:error, Ecto.Changeset.t()}
|
||||
def store_image(params) do
|
||||
%Asset{}
|
||||
|> Asset.image_changeset(params)
|
||||
|> Repo.insert(on_conflict: :nothing, returning: true)
|
||||
end
|
||||
|
||||
@spec get(String.t()) :: Asset.t() | nil
|
||||
def get(hash) do
|
||||
Repo.get(Asset, hash)
|
||||
end
|
||||
|
||||
@spec get!(String.t()) :: Asset.t()
|
||||
def get!(hash) do
|
||||
Repo.get!(Asset, hash)
|
||||
end
|
||||
|
||||
@spec total_content_size() :: non_neg_integer() | nil
|
||||
def total_content_size do
|
||||
q =
|
||||
from p in Asset, select: sum(fragment("length(content)"))
|
||||
@@ -38,6 +43,7 @@ defmodule MusicLibrary.Assets do
|
||||
Repo.one(q)
|
||||
end
|
||||
|
||||
@spec track_total_content_size() :: :ok
|
||||
def track_total_content_size do
|
||||
:telemetry.execute(
|
||||
[:music_library, :assets],
|
||||
@@ -46,6 +52,7 @@ defmodule MusicLibrary.Assets do
|
||||
)
|
||||
end
|
||||
|
||||
@spec track_total_cache_size() :: :ok
|
||||
def track_total_cache_size do
|
||||
:telemetry.execute(
|
||||
[:music_library, :assets],
|
||||
|
||||
Reference in New Issue
Block a user