1
0
Fork 0

Fixes #1187 - account for enum value change

master
Jeff Boek 2019-03-26 09:13:59 -07:00
parent edb197d10b
commit cf0d1355b5
1 changed files with 7 additions and 1 deletions

View File

@ -16,9 +16,15 @@ private class EventWrapper<T : Enum<T>>(
private val event: EventMetricType<T>,
private val keyMapper: ((String) -> T)? = null
) {
private val String.asCamelCase: String
get() = this.split("_").reduceIndexed { index, acc, s ->
if (index == 0) acc + s
else acc + s.capitalize()
}
fun track(event: Event) {
val extras = if (keyMapper != null) {
event.extras?.mapKeys { keyMapper.invoke(it.key) }
event.extras?.mapKeys { keyMapper.invoke(it.key.asCamelCase) }
} else {
null
}