elixir-toniq / vapor

Runtime configuration system for Elixir
MIT License
596 stars 37 forks source link

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

Closed gausby closed 5 years ago

gausby commented 6 years ago

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.

keathley commented 6 years ago

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)
keathley commented 5 years ago

I ended up going with this design. Thanks for the suggestion :+1: