elixir-toniq / vapor

Runtime configuration system for Elixir
MIT License
592 stars 36 forks source link

Defaults and required #61

Closed keathley closed 4 years ago

keathley commented 4 years ago

After this PR, env and file providers will allow users to pass options for each "binding". The initial options are map, required, and default. map allows users to pass a translation (a mapping function) alongside a binding. If a binding is marked as required: false then vapor will return the key with nil as the value. If a binding has a default and the value specified in the binding is missing then the default is provided. Defaults should always skip the map function.

Example

providers = [
  %Env{
    bindings: [
      {:foo, "FOO", default: 1337, map: &String.to_integer/1},
    ]
  }
]
jeffutter commented 4 years ago

I like this. It probably requires a Readme update particularly that last bit "Defaults should always skip the map function." That makes sense but might surprise some people

keathley commented 4 years ago

Yeah all of this still needs to be added to the README.