-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
hoplite-core/src/main/kotlin/com/sksamuel/hoplite/decoder/MinutesDecoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.sksamuel.hoplite.decoder | ||
|
||
import com.sksamuel.hoplite.ConfigFailure | ||
import com.sksamuel.hoplite.ConfigResult | ||
import com.sksamuel.hoplite.DecoderContext | ||
import com.sksamuel.hoplite.LongNode | ||
import com.sksamuel.hoplite.Node | ||
import com.sksamuel.hoplite.StringNode | ||
import com.sksamuel.hoplite.ThrowableFailure | ||
import com.sksamuel.hoplite.fp.Try | ||
import com.sksamuel.hoplite.fp.invalid | ||
import com.sksamuel.hoplite.fp.valid | ||
import kotlin.reflect.KType | ||
|
||
class MinutesDecoder : NonNullableLeafDecoder<Minutes> { | ||
|
||
override fun supports(type: KType): Boolean = type.classifier == Minutes::class | ||
override fun safeLeafDecode( | ||
node: Node, | ||
type: KType, | ||
context: DecoderContext | ||
): ConfigResult<Minutes> = when (node) { | ||
is StringNode -> Try { Minutes(node.value.toLong()) }.toValidated { ThrowableFailure(it) } | ||
is LongNode -> Minutes(node.value).valid() | ||
else -> ConfigFailure.DecodeError(node, type).invalid() | ||
} | ||
} | ||
|
||
data class Minutes(val value: Long) |
29 changes: 29 additions & 0 deletions
29
hoplite-core/src/main/kotlin/com/sksamuel/hoplite/decoder/SecondsDecoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.sksamuel.hoplite.decoder | ||
|
||
import com.sksamuel.hoplite.ConfigFailure | ||
import com.sksamuel.hoplite.ConfigResult | ||
import com.sksamuel.hoplite.DecoderContext | ||
import com.sksamuel.hoplite.LongNode | ||
import com.sksamuel.hoplite.Node | ||
import com.sksamuel.hoplite.StringNode | ||
import com.sksamuel.hoplite.ThrowableFailure | ||
import com.sksamuel.hoplite.fp.Try | ||
import com.sksamuel.hoplite.fp.invalid | ||
import com.sksamuel.hoplite.fp.valid | ||
import kotlin.reflect.KType | ||
|
||
class SecondsDecoder : NonNullableLeafDecoder<Seconds> { | ||
|
||
override fun supports(type: KType): Boolean = type.classifier == Seconds::class | ||
override fun safeLeafDecode( | ||
node: Node, | ||
type: KType, | ||
context: DecoderContext | ||
): ConfigResult<Seconds> = when (node) { | ||
is StringNode -> Try { Seconds(node.value.toLong()) }.toValidated { ThrowableFailure(it) } | ||
is LongNode -> Seconds(node.value).valid() | ||
else -> ConfigFailure.DecodeError(node, type).invalid() | ||
} | ||
} | ||
|
||
data class Seconds(val value: Long) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters