sarat1669

sarat1669

Module.module_info doesn't include all behaviours

I have a module which defines a behavior

defmodule Light.Trigger do
  @callback initialize(%{}) :: {:ok, any()}

  defmacro __using__(_) do
    quote do
      use GenServer
      @behaviour Light.Trigger
      ...
    end
end

And I am using it like

defmodule Light.Test do
  use Light.Trigger
  
  @impl true
  def initialize(state) do
    {:ok, state}
  end

  @impl true
  def handle_info(:test, state) do
    ...
    {:noreply, state}
  end
end

This happens

iex> Light.Test.module_info[:attributes][:behaviour]
[GenServer]

But it should be

iex> Light.Test.module_info[:attributes][:behaviour]
[GenServer, Trigger]

right?

Most Liked

John-Goff

John-Goff

You can use Keyword — Elixir v1.20.2 to get the list that you want.

Keyword.get_values(Light.Test.module_info[:attributes], :behaviour)
hauleth

hauleth

1.Use more idiomatic mod.module_info(:attributes).
2. It will mention only behaviours set via module attribute (you do not need to set that to implement behaviour). So there is no “100% correct” solution to list all implemented behaviours.

sarat1669

sarat1669

On further inspection:

iex> Light.Test.module_info[:attributes]
[
  vsn: [325461190013957173593492030108196297138],
  behaviour: [GenServer],
  behaviour: [Light.Test]
]

Where Next?

Popular in Discussions Top

andre1sk
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
jeramyRR
This is an interesting article to read. Elixir’s performance, like usual, is excellent. However, it seems like the high CPU usage is co...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19204 150
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
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
Markusxmr
Since Drab has been developed for a while in the open, introducing the Liveview functionality in a way it happend appears to undermine th...
New

Other popular topics Top

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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
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
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
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
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

We're in Beta

About us Mission Statement