The alias of the entire contents of the / namepsace module in IEX

Following the advice of this question regarding loading iex with dependencies of the current project, I was able to work quite effectively with the dependencies of the phoenix structure. However, for each thing, it is a little tedious to provide the Phoenix project namespace.

Instead of typing MyApp.Repo.all(MyApp.User) I was hoping to make Repo.all(User) . I can individually use each thing with alias MyApp.Repo, as: Repo , but is there a way to do this for everything at once?

+8
elixir phoenix-framework iex mix
source share
1 answer

You can simply call alias MyApp.Repo instead of MyApp.Repo, as: Repo - it will use the last part of the module name.

In Elixir 1.2, you can use several submodules for your names with a single call: alias MyApp.{Repo, User}

You also have the .iex.exs option, which you can use to configure your aliases. You can read about it at http://elixir-lang.org/docs/v1.1/iex/IEx.html - I would not recommend it in this case, since you run the risk of running into names. Calling alias in an iex session is more explicit.

+11
source share

All Articles