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.

Last Post!

leaf

leaf

thanks its a good solution.

Where Next?

Popular in Questions Top

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
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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement