tony612
Is there a way to get information of multiple specific modules?
I’m developing some features for GitHub - elixir-protobuf/protobuf: A pure Elixir implementation of Google Protobuf. · GitHub, but I need a way to know what modules are protobuf modules and even want to store more information for them
A protobuf module is defined like this
defmodule Foo do
use Protobuf, syntax: :proto3
end
defmodule Bar do
use Protobuf, syntax: :proto3
end
I want to get the information in runtime/compile time like
> Protobuf.all_messages
[
{Foo, some_foo_metadata},
{Bar, some_bar_metadata}
]
Is there any way to achieve this?
A direct way I can think of is to define a function for each protobuf module, and call them when the program starts. I can use ets or persistent_term to build “all_messages”. But I can’t find a callback like this.
I don’t know if this can be implemented in compiling time, but it seems hard because we can’t make sure every protobuf module is compiled every time.
First Post!
mpope
If you want to do it dynamically, you could try :code.all_loaded(). It returns a list of tuples, the first element is an atom of each module name, the second is a string of their location. You could stringify and check the first element for a constant module string. So instead of Foo you could do FooProtobuf and check for the Protobuf string. A bit hackey, but it’d work.
As for the metadata, I am unsure.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










