mirror of
https://github.com/mitchell/shortnr.git
synced 2025-12-19 14:07:22 +00:00
Setup Dialyxir and Credo code analyzers:
- Refactor codebase according to analyzers
This commit is contained in:
parent
593f29d271
commit
b699e661e2
15 changed files with 74 additions and 44 deletions
|
|
@ -1,4 +1,8 @@
|
|||
defmodule Shortnr.URL.Repo.ETS do
|
||||
@moduledoc """
|
||||
This module is an implemention of the Repo behaviour using the Erlang ETS library.
|
||||
"""
|
||||
|
||||
@behaviour Shortnr.URL.Repo
|
||||
|
||||
@impl true
|
||||
|
|
@ -16,7 +20,7 @@ defmodule Shortnr.URL.Repo.ETS do
|
|||
end
|
||||
|
||||
@impl true
|
||||
def list() do
|
||||
def list do
|
||||
resp = ets().select(:urls, [{:"$1", [], [:"$1"]}])
|
||||
{:ok, resp |> Enum.map(&elem(&1, 1))}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
defmodule Shortnr.URL.Repo do
|
||||
alias Shortnr.URL
|
||||
@moduledoc """
|
||||
This module defines the Repo behaviour for the URL service. All Repos must implement this
|
||||
entire behaviour.
|
||||
"""
|
||||
|
||||
alias Shortnr.Transport
|
||||
alias Shortnr.URL
|
||||
|
||||
@callback put(URL.t()) :: :ok | Transport.error()
|
||||
@callback get(String.t()) :: {:ok, URL.t()} | Transport.error()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
defmodule Shortnr.URL do
|
||||
@moduledoc """
|
||||
This module represents both the URL data object, in the form of a struct, and the URL business
|
||||
domain service.
|
||||
"""
|
||||
alias Shortnr.Transport
|
||||
alias Shortnr.URL
|
||||
alias Shortnr.URL.Util
|
||||
|
||||
defstruct id: "",
|
||||
|
|
@ -17,7 +20,7 @@ defmodule Shortnr.URL do
|
|||
|
||||
@spec create(String.t(), module()) :: {:ok, String.t()} | Transport.error()
|
||||
def create(url, repo) do
|
||||
url_struct = %URL{id: Util.gen_id(), url: URI.parse(url)}
|
||||
url_struct = %__MODULE__{id: Util.gen_id(), url: URI.parse(url)}
|
||||
|
||||
{:ok, extant_url} = repo.get(url_struct.id)
|
||||
|
||||
|
|
@ -29,17 +32,17 @@ defmodule Shortnr.URL do
|
|||
end
|
||||
end
|
||||
|
||||
@spec get(String.t(), module()) :: {:ok, URL.t()} | Transport.error()
|
||||
@spec get(String.t(), module()) :: {:ok, t()} | Transport.error()
|
||||
def get(key, repo) do
|
||||
{:ok, _} = repo.get(key)
|
||||
end
|
||||
|
||||
@spec list(module()) :: {:ok, list(URL.t())} | Transport.error()
|
||||
@spec list(module()) :: {:ok, list(t())} | Transport.error()
|
||||
def list(repo) do
|
||||
{:ok, _} = repo.list
|
||||
end
|
||||
|
||||
@spec delete(String.t(), module()) :: {:ok, :ignore} | Tranpsport.error()
|
||||
@spec delete(String.t(), module()) :: {:ok, String.t()} | Transport.error()
|
||||
def delete(key, repo) do
|
||||
:ok = repo.delete(key)
|
||||
{:ok, "Success"}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Shortnr.URL.Util do
|
||||
@moduledoc """
|
||||
URL module utility functions.
|
||||
"""
|
||||
@id_chars String.codepoints("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXWYZ0123456789")
|
||||
@spec gen_id() :: String.t()
|
||||
def gen_id do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue