jonotree

jonotree

Using config/3 macro when 3rd argument is not a keyword list

I’m trying to use Tzdata module, and according to the Getting Started section of the hexdoc

, the following config should be used:

config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase

Issue 1
When trying to follow this I had the problem of having no config file in my project (generated using mix new projectname) - I’ve provisionally created config/config.exs at the root, with use Mix.Config at the top, based on previous example project. However, documentation about config states that depending on whether you want that the config info to influence the initial build, or be accessible at runtime, you should use put it in runtime.exs or config.exs.
In the case I’m not sure which is appropriate - should it be in config.exs?

Issue 2
Secondly, I’ve updated to a newer version of Elixir (1.13.3) since making the previous example project, and now I’m being warned that Mix.Config is deprecated.In order to migrate to the newer Config module, I want to understand what the line config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase actually does. Looking at the documentation of Mix.Config.config/3, I would expect the arguments to be: root element, key, options (keyword list?) - but here we have:
root element = Elixir
key = :time_zone_database
options(s) = Tzdata.TimeZoneDatabase

Specifying the options as Tzdata.TimeZoneDatabase surely does not pass for a keyword list, so what’s going on here?

Marked As Solved

cmo

cmo

You probably want that one in config.exs.

You often have these files:

config/
- config.exs
- dev.exs
- prod.exs
- runtime.exs
- test.exs

config.exs is your base config and others are imported afterwards, depending on the environment, like so:

# This file is responsible for configuring your application
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.

# General application configuration
import Config

... your config here ...

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"

If you’re using releases, runtime.exs will end up in the release directory, so you can edit it after the fact. The others will vanish, like magic (or be compiled).

All the config will end up in your Application env, which you can retrieve using Application.fetch_env/get_env and friends. Notice the typespec for Application.put_env is put_env(app(), key(), value(), timeout: timeout(), persistent: boolean()) :: :ok, where value() :: term().

Config.config/3 is config(root_key, key, opts). It talks about keyword lists, which may lead us to think we can only put keyword lists in there, but as we can see from our config files, and Application.put_env, we can jam just about anything in there. Typically it is either a single value or a keyword list.

Where Next?

Popular in Questions Top

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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement