Would it be possible for Mix.Config
's config
to be a macro which creates accessor functions for the environment variables? E.g.:
# config/config.exs
config :my_app, :key, "value"
…currently enables this kind of access:
"value" = Application.fetch_env!(:my_app, :key)
But instead, I imagine the config
macro generates functions at compile time enabling this usage:
"value" = Application.MyApp.key()
The big win is the compile-time checking & LS completion support for MyApp
and key
. It’s also shorter and more expressive. It doesn’t rely on the programmer remembering to use fetch_env!
vs. get_env
.
I’m new to macros as well as the Application
+ Mix.Config
system. Would this be possible?
Update: A couple of existing solutions are,