srowley

srowley

Using static files in a library

I have a library that uses some static (.csv) files in certain functions, i.e., you call the function, and it reads one of these files and produces an output. These functions are mostly used in mix tasks for development/testing purposes. There is however some possibility that someone would want to use them in production, so I am considering including them when I publish the library to hex.

Given this, I have two questions:

  1. Is there a convention as to what directory this type of file goes in? (There was a similar question asked this morning but I think the circumstances might be a little different)

  2. In dev/test, the path for the directory where I tentatively keep the files is top_level/datasets, but if this package is included in some other project the path will be top_level/deps/library_name/datasets. I think I could just modify the functions to use the right path at compile time using Mix.env but using Mix.env for almost anything seems to be frowned upon, so I am not confident that is the best approach.

Marked As Solved

Eiji

Eiji

This is not related to CSV, but it may be a good source of inspiration:

Following ElixirSchool you should use Application.app_dir/2:

Application.app_dir(:app_name, "priv/datasets")
# or
Path.join(:code.priv_dir(:app_name), "datasets")

Libraries which may be helpful for you:

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New

We're in Beta

About us Mission Statement