vic

vic

Asdf Core Team

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

tmbb

Very cool :smiling_face_with_sunglasses:

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 - :joy:) 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

vic

Asdf Core Team

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.

:slight_smile:

OvermindDL1

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…

Where Next?

Popular in Announcing Top

danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
kip
ex_cldr provides localisation and internationalisation support based upon the data from the Unicode CLDR project. Unicode released CLDR ...
407 12840 120
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
cjen07
parameterized pipe in elixir: |n> edit: negative index in |n> and mixed usage with |> are supported example: use ParamPipe ...
New
josevalim
Hello everyone, We have just released NimbleCSV which is a small and fast CSV parsing library for Elixir. It allows developers to define...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
144 10187 141
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New

Other popular topics Top

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement