vic
Deco - minimal function decorators with around advice
Yep, yet another library for function decorators in Elixir. This one however, is smaller and simple
defp is_authorized(decorated, conn, params) do
if conn.assigns.user do
decorated.(conn, params)
else
conn
|> send_resp(401, "unauthorized")
|> halt()
end
end
deco {Deco.around(is_authorized)} in
def create(conn, params) do
...
end
Most Liked
tmbb
Very cool ![]()
Not in the sense thatbI’d ever use it, but in the sence that it makes me want to use it, even though I probably shouldn’t…
I’ve written a similar thing, which I’ve named Doktor. It’s like you regular old Doc, but younger, cooler and more radiKal. Because it had a K. It allows you to write this:
defmodule My.Module do
use Doktor, "dok/docstrings_for_my_module.md"
@moduledok "My.Module"
@dok "hey/0"
def hey(), do: "Hey!"
@dok "hello/1"
def hello(name), do: "Hello #{name}!"
end
Basically, Doktor takes up an Markdown (MD -
) file annotated in a special way and, extracts docstrings from that file and documents the functions with those docstrings. This kan help deKlutter your modules, because it moves the doKstrings somewhere else. I’m still not sure on how useful this is (or whether it is even a good thing at all), but it’s just so KOOL xD
The way it works is by overwriting the @ operator inside the use macro so that it treats the @dok, @moduledok and @typedok` In a special way. Although it’s completely different, it reminded me of this somehow.
vic
haha you got me, I’m always looking at what things I’m able to do with the Elixir syntax, and yeah, the formatter doesnt like it that much, maybe in could be treated just like do and allow a new line after it.
Hey Doktor looks awesome, I’ve been using just @moduledoc File.read!("README.md") but your tool looks nice. One thing I’ve noticed while running tests from an .md file is, I need to modify the .ex file importing it for the new tests to take place, otherwise it’s already compiled with no changes. How you’d handle that in doktor.
![]()
OvermindDL1
I like this trick of linking with in here! I wonder how the formatter formats that though, hmm…
Testing…
iex(1)> Code.format_string!("""
...(1)> deco {Deco.around(is_authorized)} in
...(1)> def create(conn, params) do
...(1)> ...
...(1)> end
...(1)> """) |> IO.puts()
deco {Deco.around(is_authorized)} in def(create(conn, params)) do
...
end
Aww that’s sad, and no way to fix the formatter for this either currently…
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








