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

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement