Search code examples
jsondata-structuresconfigurationelixirelixir-mix

External Application Configuration in Elixir


I'm having a bit of an issue getting external application configuration working. I'm currently writing a text-based adventure game to learn Elixir. I am thinking of storing "room" definitions as JSON in an "assets" directory.

Here's a look at my directory structure:

.
├── _build
│   ├── dev
│   └── test
├── assets
│   ├── rooms  <---
│   └── items
├── config
├── deps
│   └── poison
├── lib
│   └── myzork
└── test

I have tried Application.app_dir/1 & Application.app_dir/2, but those reference files under _build when I use iex -S mix.

How would I get this directory to ship with my code? Is there an elixir-way to reference these files? Or am I going about this in a totally incorrect way?


Solution

  • If you want to bring those assets with you when you build and ship the application then I suggest putting them inside priv (like priv/assets), so that Application.app_dir(:my_app, "priv") will easily retrieve them.

    Your use case however suggests that you may need those assets only during compilation (in order to generate Elixir representations of those rooms at compile time). If so, then put them wherever you want and just read them in, wherever they are - use functions like File.cwd/1 and similar to build the path to them.