How to access "require" contents?

Hello everyone,

I want to check a module if it uses require and access the require contents
Module.definitions_in MODULE "this doesn’t include any info about the [use, require] ! "

Thank you very much

@elixir_guy Can you explain what are you trying to do with such information from module?

The user will have to require modules to create relations, i can work around it by creating a marco, but this mean the user will have to require modules and define them . So if there is a way to access it at the compile time will be really helpful.

hmm, sorry but I did not get it

By user you mean end-user which uses front-end (or equivalent interface)? Your description would make more sense if you are writing library and you are trying to do something for developers. I do not see why user would need to work with code.

You are describing it with a bit too less details. For example I do not get what you mean by require modules to create relations. Look that relations could be interpreted as ecto relations (belongs to, has many, has one, many to many) which does not require to call require or use to use already created schema.

To check if module is calling use you need to have some introspection like ecto and other libraries have. For example:

defmodule Example do
  defmacro __using__(_opts \\ []) do
    quote do
      def __is_example__, do: true
    end
  end
end

defmodule Sample do
  use Example
end

if :erlang.function_exported(Sample, :__is_example__, 0) do
  IO.puts("module is calling `use Example`")
else
  IO.puts("module is not calling `use Example`")
end

Sorry for not providing more details,
Forget about “use”
There are [alias, import, use, require],
Say a module X do

require {ModuleY, ModuleW, etc}

This mean all the required modules will get compiled before ModuleX, consider each module is a struct, and
Struct ModuleX require some values from the ModuleY at the compile time. So what i was looking at is to check if the ModuleX is using “require” and then access them to get the value from the struct.

anyway will work around it if not possible

Thank you

Can you show some concrete code you’re trying to make work?