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]
]

Last Post!

bit4bit

bit4bit

see model_info i think it’s work as expected:

Returns a list of {AttributeName,ValueList} tuples,
where AttributeName is the name of an attribute, and ValueList is a list of values.
Notice that a given attribute can occur more than once in the list with different values if the attribute occurs more than once in the module.

Where Next?

Popular in Discussions Top

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
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18595 126
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
AstonJ
Can you believe the first professionally published Elixir book was published just 8 years ago? Since then I think we’ve seen more books f...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
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 54996 245
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
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement