-
Notifications
You must be signed in to change notification settings - Fork 141
/
application.ex
46 lines (38 loc) · 1.13 KB
/
application.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
defmodule Protobuf.Application do
use Application
@moduledoc """
When extensions feature is enabled, all modules are scanned to fetch
runtime information for extensions, see `Protobuf.Extension` for details.
No children are created now.
"""
@doc false
@impl true
def start(_type, _args) do
Protobuf.Extension.__cal_extensions__(get_all_modules())
Supervisor.start_link(_children = [], strategy: :one_for_one)
end
@doc false
@impl true
def stop(_state) do
Protobuf.Extension.__unload_extensions__()
:ok
end
defp get_all_modules do
case Application.get_env(:protobuf, :extensions) do
:enabled ->
case :code.get_mode() do
:embedded ->
:erlang.loaded()
:interactive ->
Enum.flat_map(Application.loaded_applications(), fn {app, _desc, _vsn} ->
{:ok, modules} = :application.get_key(app, :modules)
modules
end)
end
_disabled ->
# Extensions in Protobuf are required for generating code
{:ok, mods} = :application.get_key(:protobuf, :modules)
mods
end
end
end