From de77b1b2a2f1ad1a89eaa3502ec4293c94db6905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20M=C3=A4nnchen?= Date: Mon, 14 Dec 2020 22:05:28 +0000 Subject: [PATCH] Fix Dialyzer Specs (#120) --- lib/paper_trail/version_queries.ex | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/paper_trail/version_queries.ex b/lib/paper_trail/version_queries.ex index d1b8ab82..dd9a93b6 100644 --- a/lib/paper_trail/version_queries.ex +++ b/lib/paper_trail/version_queries.ex @@ -15,17 +15,17 @@ defmodule PaperTrail.VersionQueries do iex(1)> PaperTrail.VersionQueries.get_versions(ModelName, id) iex(1)> PaperTrail.VersionQueries.get_versions(ModelName, id, [prefix: "tenant_id"]) """ - @spec get_versions(record :: Ecto.Schema.t()) :: Ecto.Query.t() + @spec get_versions(record :: Ecto.Schema.t()) :: [Version.t()] def get_versions(record), do: get_versions(record, []) @doc """ Gets all the versions of a record given a module and its id """ - @spec get_versions(model :: module, id :: pos_integer) :: Ecto.Query.t() + @spec get_versions(model :: module, id :: pos_integer) :: [Version.t()] def get_versions(model, id) when is_atom(model) and is_integer(id), do: get_versions(model, id, []) - @spec get_versions(record :: Ecto.Schema.t(), options :: []) :: Ecto.Query.t() + @spec get_versions(record :: Ecto.Schema.t(), options :: []) :: [Version.t()] def get_versions(record, options) when is_map(record) do item_type = record.__struct__ |> Module.split() |> List.last() @@ -33,7 +33,7 @@ defmodule PaperTrail.VersionQueries do |> PaperTrail.RepoClient.repo().all end - @spec get_versions(model :: module, id :: pos_integer, options :: []) :: Ecto.Query.t() + @spec get_versions(model :: module, id :: pos_integer, options :: []) :: [Version.t()] def get_versions(model, id, options) do item_type = model |> Module.split() |> List.last() version_query(item_type, id, options) |> PaperTrail.RepoClient.repo().all @@ -52,14 +52,14 @@ defmodule PaperTrail.VersionQueries do iex(1)> PaperTrail.VersionQueries.get_version(ModelName, id) iex(1)> PaperTrail.VersionQueries.get_version(ModelName, id, [prefix: "tenant_id"]) """ - @spec get_version(record :: Ecto.Schema.t()) :: Ecto.Query.t() + @spec get_version(record :: Ecto.Schema.t()) :: Version.t() | nil def get_version(record), do: get_version(record, []) - @spec get_version(model :: module, id :: pos_integer) :: Ecto.Query.t() + @spec get_version(model :: module, id :: pos_integer) :: Version.t() | nil def get_version(model, id) when is_atom(model) and is_integer(id), do: get_version(model, id, []) - @spec get_version(record :: Ecto.Schema.t(), options :: []) :: Ecto.Query.t() + @spec get_version(record :: Ecto.Schema.t(), options :: []) :: Version.t() | nil def get_version(record, options) when is_map(record) do item_type = record.__struct__ |> Module.split() |> List.last() @@ -67,7 +67,7 @@ defmodule PaperTrail.VersionQueries do |> PaperTrail.RepoClient.repo().one end - @spec get_version(model :: module, id :: pos_integer, options :: []) :: Ecto.Query.t() + @spec get_version(model :: module, id :: pos_integer, options :: []) :: Version.t() | nil def get_version(model, id, options) do item_type = model |> Module.split() |> List.last() last(version_query(item_type, id, options)) |> PaperTrail.RepoClient.repo().one @@ -76,6 +76,7 @@ defmodule PaperTrail.VersionQueries do @doc """ Gets the current model record/struct of a version """ + @spec get_current_model(version :: Version.t()) :: Ecto.Schema.t() | nil def get_current_model(version) do PaperTrail.RepoClient.repo().get( ("Elixir." <> version.item_type) |> String.to_existing_atom(),