Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get application name in umbrella project

Tags:

elixir

I have an umbrella project (my_app) like this:

├── README.md ├── apps │ ├── app_one │ | └── mix.exs │ ├── app_two | | └── mix.exs │ └── ... ├── config └── mix.exs

I want to get the name of the currently running app,
for example: app_one , app_two.
when i use:
Mix.Project.get.project[:app]
i always get the main project name my_app .
How can i do that?

like image 207
fay Avatar asked Dec 24 '22 18:12

fay


1 Answers

You can get the application to which the a module belongs to using :application.get_application/1. If you pass __MODULE__ as the first argument, you'll get the application the current module belongs to.

$ cat apps/a/lib/a.ex
defmodule A do
  def hello do
    :application.get_application(__MODULE__)
  end
end
$ cat apps/b/lib/b.ex
defmodule B do
  def hello do
    :application.get_application(__MODULE__)
  end
end
$ iex -S mix
iex(1)> A.hello
{:ok, :a}
iex(2)> B.hello
{:ok, :b}
like image 119
Dogbert Avatar answered Dec 30 '22 20:12

Dogbert