elixir-toniq / vapor

Runtime configuration system for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A thought on `VaporExample.Config.get_…/1`

gausby opened this issue · comments

The calls of this form:

VaporExample.Config.get_int("config_key")

Wouldn't it be more extensible, and cleaner to say:

VaporExample.Config.get("config_key", as: :int)

That way one could make their own data coercers that coerced the value into something that makes sense for their application. Just a thought.

In my head I had assumed that users could use whichever coercion function they needed for any given key. So

Config.get_int("key")
Config.get_string("key")
Config.get_bool("key")

Would all be valid uses. That said I think that passing the "coercion method" as an argument could be useful and could theoretically be extended to allow users to pass in functions if they needed custom coercion methods like so:

Config.get("key", as: fn (value) -> my_custom_coercion(value) end)

I ended up going with this design. Thanks for the suggestion 👍