blisscs

blisscs

Question on :application.get_key(:my_app, :module)

As I understand :application.get_key(:my_app, :module) lists all of compiled modules under the :my_app application. I have a question when we create a module during runtime. The created module is not listed as a result of running application.get_key(:my_app, :module)

Please see the case before -

defmodule MyAppTest do
  use ExUnit.Case
  doctest MyApp

  test "get modules" do
    defmodule MyApp.A do
      def a(), do: "a"
    end

    assert "a" == MyApp.A.a() # This one works

    {:ok, modules} = :application.get_key(:my_app, :modules)
    assert MyApp.A in modules # Why this line is failing. How can I get all the compiled modules at this time?

    after
    purge(MyApp.A)
  end

  defp purge(module) do
    :code.delete(module)
    :code.purge(module)
  end
end

Are there any other functions to fetch for the compiled modules at the current time?

I am doing as above, I only want this module during the test time and only for this specific test, i.e, I don’t want this module to be available during running other tests.

Most Liked

NobbZ

NobbZ

The list returned from :application.get_key/2 is compiled from the applications manifest, which again is created by mix.

Runtime created modules do not belong to any application, and as far as I remember there is no way to get a list of them.

Though you might be able to use :code.all_loaded/0 to get a list of all currently loaded modules.

Last Post!

NobbZ

NobbZ

Enable embedded mode in your mix.exs and try again. The default is to lazy load modules. Embedded mode will load all modules at VM boot time.

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
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 55125 245
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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

We're in Beta

About us Mission Statement