Any insights on generating a config.exs programmatically?

81 views
Skip to first unread message

Narcissus Emi

unread,
Aug 1, 2016, 6:21:22 AM8/1/16
to elixir-lang-talk
Hi,

I'm now running a project which needs to generate config file based on user configurable key/value pair, I would like to create a user.exs(imported from config.exs) to before recompile and deploy the file all programmatically,currently I'm stucked at creating this exs file part.

Since a exs is just a valid keyword list, I think maybe using IO.inspect(keywords) and write to a file is already enough? Or is there any libs or methods we can do it more elegantly?

Hope anybody came across similar problem before, any help would be real appreciate :)

OvermindDL1

unread,
Aug 1, 2016, 10:01:28 AM8/1/16
to elixir-lang-talk
Large variety of ways of taking this.  Where are the key/values coming from and why can they not be put in a normal configuration file first?

Narcissus Emi

unread,
Aug 1, 2016, 11:21:02 AM8/1/16
to elixir-lang-talk
most config items are from db, so is hard to generate from normal configuration, and they might change the way how code is being generated as well.
I went back to use import_config in together with a mix task to create a config file by using Macro.to_string(quote bind_quotes: [value: value] do
use Mix.Config
config app,
key: value
end) before doing exrm release.

在 2016年8月1日星期一 UTC+8下午10:01:28,OvermindDL1写道:

OvermindDL1

unread,
Aug 1, 2016, 11:27:42 AM8/1/16
to elixir-lang-talk
Technically the Mix.Config files are full code, you could access the database within them and use values you get from there (I actually do a few things kind of like that for certain environment things that I cannot get from the environment).

Narcissus Emi

unread,
Aug 1, 2016, 11:36:24 AM8/1/16
to elixir-lang-talk
Yeps, that works, but I need something work like this.
mix generate_config name(so I can generate a config before compiling start to update the current config)
MIX_ENV=prod mix compile && MIX_ENV=prod mix release
scp rel/target.tar.bz2 server/name
if I do use db access in Config, I have no idea how argument can be sent into,so I end up with Macro which works good and easier to log with.



在 2016年8月1日星期一 UTC+8下午11:27:42,OvermindDL1写道:

Michał Muskała

unread,
Aug 1, 2016, 12:40:03 PM8/1/16
to elixir-l...@googlegroups.com
You could take a look at how phoenix.new works. It creates config.exs with some initial values. This should be a good starting point.

Michał.
> --
> You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/f4cc9a4c-5a83-43b5-8c4b-d9dd72f57b92%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

Onorio Catenacci

unread,
Aug 2, 2016, 8:00:15 AM8/2/16
to elixir-lang-talk
That's a great suggestion @Michał!
Reply all
Reply to author
Forward
0 new messages