ficus icon indicating copy to clipboard operation
ficus copied to clipboard

Convert config to object without needing a key

Open williamho opened this issue 9 years ago • 3 comments

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

williamho avatar Dec 17 '15 21:12 williamho

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 avatar May 15 '16 07:05 shanielh

@shanielh that sounds sane to me.

kailuowang avatar May 15 '16 11:05 kailuowang

@kailuowang Great, I'll send a PR until Tuesday.

shanielh avatar May 15 '16 11:05 shanielh