ficus
ficus copied to clipboard
Convert config to object without needing a key
Currently it's not possible to do:
config.as[MyClass]
As a workaround, a dummy key has to be used:
val dummyKey = "dummy-key"
config.atKey(dummyKey).as[MyClass](dummyKey)
https://github.com/ceedubs/ficus/issues/10#issuecomment-68707348
Actually, I would really like this too.
I guess that the fix is to add another overload to as[X]
method that uses this workaround, This won't work with readers that read values using config.getString
or other primitives, since you won't be able to get the config in the first place.
We can create implicit values for readers that uses only config.getConfig
and get them implicitly in the as[X]
overload, so that a compile error will be shown when someone tries to do config.as[String]
.
update: Thinking about this again, we can add another trait like value reader that has a method read(config: Config)
, and get that trait implicitly (instead of ValueReader[A]
) in config.as[X]
@kailuowang What do you think?
@shanielh that sounds sane to me.
@kailuowang Great, I'll send a PR until Tuesday.