Rich_Morin

Rich_Morin

Not sure how to document defdelegate entries

Dave Thomas suggests that folks put the interface definition for a component into lib/foo.ex, then put all the implementation code into lib/foo/*.ex. I’ve been using this approach and like it a lot, but I’m not sure how to document the defdelegate entries.

Although I could put all of the interface documentation into lib/foo.ex, this would defeat much of the purpose of using lib/foo/*.ex. The @doc entries would be separated from the code and the lib/foo.ex file would become awkwardly large.

So, I’ve been using placeholder @moduledoc and @doc entries in lib/foo.ex, containing links to the “real” documentation, as follows:

@moduledoc """
This module defines the external API for the Common component.
Each "function" actually delegates to a public function in
`common/*.ex`.
"""

@doc """
Split a comma-delimited string into a list of trimmed strings.
([`...Strings.str_list/1`](Common.Strings.html#str_list/1))
"""
defdelegate str_list(in_str),       to: Strings

However, this seems a bit tedious. Am I missing an easier WTDI?

-r

Most Liked

domvas

domvas

There is a metadata available in ExDoc for this (and well hidden too…)

@doc delegate_to: {M, F, A}

that will print See M.F/A

Example:
Considering:

defmodule DelegateDoc.Sub do
  @doc """
  This is my delegated func doc
  """
  def my_delegate(_arg) do
    # do stuff
  end
end

defmodule DelegateDoc do
  @moduledoc """
  Documentation for DelegateDoc.
  """

  @doc deletegate_to: {DelegateDoc.Sub, :my_func, 1}
  defdelegate my_delegate(arg), to: DelegateDoc.Sub
end

will end up like this in docs:
delegate_doc_exmple
Sorry I don’t know how to embed images…

And @doc deletegate_to: &DelegateDoc.Sub.my_func/1 will work too

josevalim

josevalim

Creator of Elixir

Yes! Note this metadata is automatically set by defdelegate too.

Rich_Morin

Rich_Morin

I couldn’t get this to work:

@doc delegate_to: &DelegateDoc.Sub.my_func/1

but the first format seems to work fine.

Where Next?

Popular in Questions Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement