I’m writing my own package, MyPackage, as a test exercise. While I wrote it, I used some options in its config/config.exs file.
Now that I’m using the package (after being published) in another Elixir app, I’m not able to supply the same keys in the new app’s config/config.exs. Some code for context
The MyPackage code needs this config value in order to work correctly, but all it gets is nil.
#app_using_my_package/deps/my_package/lib/code.ex
defmodule MyPackage.Code do
def some_function do
Application.get_env(:my_package, :index) # this is nil instead of "some value"
end
end
I know I wrote something wrong in my_package but I haven’t found a way to solve this.
You should be able to use config the same way. Your just not going to be putting it in the libraries config(they are not included with deps.get). So the configs you would normally put there will now be put in a higher level config that is using the package. So example if your using phoenix you would put your graveyard configs inside the phoenix config files.
Yes that would be one way of resolving your issue.
From what I know when resolving this same issue you should never set a module attribute to something from your config. If someone knows more they may correct me but as far as I know you are not suppose to do that because its compile time set.
Or your could just embed the Application.get_env/2 call inside the function where it is used. Also, I’ve switched to using Application.fetch_env!/2 in most places in my code because I always expect the System Environment variables to be set (the code in question runs on heroku so environment variables are used for lots of configuration).