# runtime.exs
config :foo, MyThing, [...]
Application.get_env(:foo, MyThing)
The problem is Application.get_env
here only shows the compile time config, not the config that was just set by the config/3
line.
The use case is this… our runtime.exs is really big and messy, so we want to split it up into separate files like so…
if System.get_env("CI") do
Code.require_file("ci.exs", "config/runtime")
end
The problem is that ci.exs
needs to modify connection information (like host/port) for config that was set in runtime.exs.
Is there a good way to do this? Thanks for the help!
Gah, I just realized it doesn’t matter. ci.exs
can just overwrite whatever it wants, and it doesn’t need to read existing values to do so. Not sure even sure what I was thinking in the first place.
Still, I’m curious why Application.get_env
doesn’t get things immediately written by config/3
.
Because that’s how it works…
defmodule Config do
defp put_config(value), do: Process.put(@config_key, value)
def config(root_key, opts) when is_atom(root_key) and is_list(opts) do
unless Keyword.keyword?(opts) do
raise ArgumentError, "config/2 expected a keyword list, got: #{inspect(opts)}"
end
get_config!()
|> __merge__([{root_key, opts}])
|> put_config()
end
end
So you can access it with Process.get({Config, :config})
, but I’d suggest not to do this.