Going through the Programming Phoenix >= 1.4 and I’m a little confused if there has to be a mapping between a module name and project file structure.
Eg in the book (ebook version) there is there instruction to create file “controllers_views_templates/listings/rumbl/lib/rumbl/accounts/accounts.ex”. I’ll expect the module for such a file to be:
defmodule Rumbl.Accounts.Accounts do
....
end
but the code sample given is this:
defmodule Rumbl.Accounts do
...
end
In the same book the file with:
defmodule Rumbl.Accounts.User do
...
end
can be found in “controllers_views_templates/listings/rumbl/lib/rumbl/accounts/user.ex” which is what I’ll expect.
Don’t worry You are not the only one to have this question.
TLDR; There is no relation between filename, directory and module name. You should adopt your own convention. In the end, module names are just atoms, as You can see with i command…
iex> i Code.Formatter
Term
Code.Formatter
Data type
Atom
Module bytecode
/Users/sqrt/.asdf/installs/elixir/1.7.3-otp-21/bin/../lib/elixir/ebin/Elixir.Code.Formatter.beam
Source
/home/ubuntu/bob/tmp/412672862f47582cfc8e244ce57c682a/elixir/lib/elixir/lib/code/formatter.ex
Version
[226900569409235149567530218176092212642]
Compile options
[]
Description
Call Code.Formatter.module_info() to access metadata.
Raw representation
:"Elixir.Code.Formatter"
Reference modules
Module, Atom
Implemented protocols
IEx.Info, Inspect, String.Chars, List.Chars
Coming from Java, I think it’s nice to make the directory structure match the module names, at least most of the time. It helps code navigation regardless of if you are using an IDE, or clicking through links on Github, or using Vim.