Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specs #20

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/francis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ defmodule Francis do

defoverridable(start: 2)

defp handle_response(handler, conn, status \\ 200) do
@spec handle_response(
(Plug.Conn.t() -> binary() | map() | Plug.Conn.t()),
Plug.Conn.t(),
integer()
) :: Plug.Conn.t()
def handle_response(handler, conn, status \\ 200) do
case handler.(conn) do
res when is_struct(res, Plug.Conn) ->
res
Expand Down Expand Up @@ -79,6 +84,7 @@ defmodule Francis do
end
```
"""
@spec get(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
defmacro get(path, handler) do
quote location: :keep do
Plug.Router.get(unquote(path), do: handle_response(unquote(handler), var!(conn)))
Expand All @@ -100,6 +106,7 @@ defmodule Francis do
end
```
"""
@spec post(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
defmacro post(path, handler) do
quote location: :keep do
Plug.Router.post(unquote(path), do: handle_response(unquote(handler), var!(conn)))
Expand All @@ -121,6 +128,7 @@ defmodule Francis do
end
```
"""
@spec put(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
defmacro put(path, handler) do
quote location: :keep do
Plug.Router.put(unquote(path), do: handle_response(unquote(handler), var!(conn)))
Expand All @@ -142,6 +150,7 @@ defmodule Francis do
end
```
"""
@spec delete(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
defmacro delete(path, handler) do
quote location: :keep do
Plug.Router.delete(unquote(path), do: handle_response(unquote(handler), var!(conn)))
Expand All @@ -163,6 +172,7 @@ defmodule Francis do
end
```
"""
@spec patch(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
defmacro patch(path, handler) do
quote location: :keep do
Plug.Router.patch(unquote(path), do: handle_response(unquote(handler), var!(conn)))
Expand All @@ -184,6 +194,7 @@ defmodule Francis do
end
```
"""
@spec ws(String.t(), (binary() -> binary() | map())) :: Macro.t()
defmacro ws(path, handler) do
module_name =
path
Expand Down Expand Up @@ -237,6 +248,7 @@ defmodule Francis do
@doc """
Defines an action for umatched routes and returns 404
"""
@spec unmatched((Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
defmacro unmatched(handler) do
quote location: :keep do
match _ do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Francis.MixProject do
use Mix.Project

@version "0.1.5"
@version "0.1.6"

def project do
[
Expand Down
Loading