HOW? Is there an outline I can follow? I have build a file parser I need to pipe into phoenix. I have included it in the deps but its not found in the namespace… I have zero idea what Im doing wrong so any thing would be helpful.
How then do I access the modules? Can you give me an outline of the expected project structure so that when the dep is loaded its is available in the name space?
its multi module. I started with a simple file / Code.require_file(path) model. Im some where between there and post mix new. I created a new project with mix new then just moved the files into lib. I literally have no idea how this works…
If it’s in the lib directory then it’s already a part of your project and you should remove that entry from the deps part of the mix.exs file. Everything inside lib gets automatically compiled, you don’t need to lift a finger about it.
If you want to use it as an external dependency then you either put it outside of your project’s directory entirely (as @kokolegorille is showing you) or put it in a separate GitHub repo and refer to it in mix.exs like that:
That’s likely because you need to alias it to use it.
Show us the first line definition of LogParser, please?
Example: it might be e.g. defmodule SomeLibrary.LogParser do ... in which case you need to have alias SomeLibrary.LogParser at the top of the Elixir file in which you want to use it.
deps are like libraries in other languages. Usually it’s code you didn’t write, or code that you might want to share across multiple projects and repos.
In Elixir they come in two flavours
A “library” - a bundle of modules and functions and data OR
An “application” - which is something that starts its own supervision tree, or which runs under a supervisor and so must be “started” when your app starts.
An example of 1. might be decimal
An example of 2 might be prometheus
Most of the time deps are imported from Hex which is Elixir’s package manager. So adding a dep (usually) instructs mix (the build tool) to fetch the dep from Hex and compile it as part of your application.
If instead you specify a dep like this:
{:parser, github: "your_name/your_project"}
You are telling mix to get the dep from github. You can also do this:
{:parser, path: "local/path/to/repo"}
But that is usually only for local debugging.
So in general, you would expect code you write to first just exist in lib. If you need to share across multiple projects you can create a library and publish it on Hex.