leaf

leaf

Writing docs for macro methods

I have this macro for which I am writing @doc and @moduledoc. The @moduledoc works fine, but @doc doesn’t show anything inside the macro. Is there any way I can write docs for the macro methods?

defmodule Paginator do
@moduledoc """
   paginator
"""  
defmacro __using__(options) do
  quote location: :keep do
    import Ecto.Query

    @options unquote(options)

   @doc """
      Apply limit and offset to the query if not provided and return meta.  
   """
     def paginate(query, params) do
     end
   end
  end
end

Most Liked

hauleth

hauleth

The pattern used by Ecto in such libraries is to define documented callbacks, so you would do something like:

defmodule Paginator do
  @moduledoc """
  paginator
  """  
  defmacro __using__(options) do
    quote location: :keep do
      import Ecto.Query

      @behaviour unquote(__MODULE__)

      @options unquote(options)

      def paginate(query, params) do
      end
    end
  end

  @doc """
  Apply limit and offset to the query if not provided and return meta.
  """
  @callback paginate(query :: Ecto.Queryable.t(), params :: keyword()) :: Ecto.Queryable.t() 
end
benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

@leaf the Paginator does not actually contain the function paginate. A module that did use Paginator would have that function, but the Paginator module does not, so there’s nothing to document.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
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
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
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
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
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
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
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

We're in Beta

About us Mission Statement