Coverage Summary for Class: NetworkEitherPlugin (com.javiersc.network.either.ktor)
Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
NetworkEitherPlugin |
100%
(2/2)
|
|
100%
(3/3)
|
100%
(20/20)
|
NetworkEitherPlugin$1 |
0%
(0/1)
|
|
0%
(0/1)
|
0%
(0/2)
|
NetworkEitherPlugin$Companion |
100%
(3/3)
|
|
100%
(6/6)
|
100%
(26/26)
|
NetworkEitherPlugin$Config |
100%
(1/1)
|
|
100%
(2/2)
|
100%
(11/11)
|
NetworkEitherPlugin$Config$isNetworkAvailable$1 |
100%
(1/1)
|
|
100%
(1/1)
|
100%
(2/2)
|
Total |
87.5%
(7/8)
|
|
92.3%
(12/13)
|
96.7%
(59/61)
|
package com.javiersc.network.either.ktor
import com.javiersc.network.either.ktor._internal.interceptBeforeTransformAndReplaceContainerWithNetworkEitherType
import com.javiersc.network.either.ktor._internal.interceptExceptionsAndReplaceWithNetworkEitherFailures
import com.javiersc.network.either.ktor._internal.interceptSuccessesAndReplaceWithNetworkEitherSuccess
import com.javiersc.network.either.utils.isNetworkAvailable as isNetAvailable
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpClientPlugin
import io.ktor.util.AttributeKey
public class NetworkEitherPlugin(
private val isNetworkAvailable: () -> Boolean = { isNetAvailable }
) {
public class Config {
public var isNetworkAvailable: () -> Boolean = { isNetAvailable }
}
public companion object : HttpClientPlugin<Config, NetworkEitherPlugin> {
override val key: AttributeKey<NetworkEitherPlugin> = AttributeKey("NetworkEither")
override fun install(plugin: NetworkEitherPlugin, scope: HttpClient) {
interceptExceptionsAndReplaceWithNetworkEitherFailures(scope, plugin.isNetworkAvailable)
interceptBeforeTransformAndReplaceContainerWithNetworkEitherType(scope)
interceptSuccessesAndReplaceWithNetworkEitherSuccess(scope)
}
override fun prepare(block: Config.() -> Unit): NetworkEitherPlugin {
val config = Config().apply { block() }
return NetworkEitherPlugin(config.isNetworkAvailable)
}
}
}