generated from mpetuska/template-kmp-library
-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
13 changed files
with
98 additions
and
107 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,33 @@ | ||
package dev.petuska.kon | ||
|
||
import dev.petuska.kon.util.toJson | ||
|
||
/** A [MutableMap] to represent a JSON object. */ | ||
public typealias TypedKON<V> = MutableMap<String, V> | ||
|
||
/** A wrapper around [MutableMap] to represent a JSON object */ | ||
public interface TypedKObject<V> : TypedKON<V> { | ||
/** | ||
* Adds a field | ||
* @receiver field name | ||
* @param value field value | ||
*/ | ||
@KONSetterDsl | ||
public infix fun String.to(value: V) { | ||
this@TypedKObject[this] = value | ||
} | ||
} | ||
|
||
/** | ||
* Builds an object. Overrides [Any::toString] to return JSON object notation. | ||
* @param obj object builder | ||
*/ | ||
@KONBuilderDsl | ||
public inline fun <V> kobj( | ||
base: TypedKON<V> = mutableMapOf(), | ||
obj: TypedKObject<V>.() -> Unit = {} | ||
): TypedKObject<V> = | ||
object : TypedKObject<V>, TypedKON<V> by base { | ||
override fun toString(): String = toJson() | ||
} | ||
.apply(obj) |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package dev.petuska.kon | ||
|
||
/** Marks DSLs with side effects that build and sets entities */ | ||
@DslMarker @Retention(AnnotationRetention.SOURCE) public annotation class KONSetterDsl | ||
@DslMarker @Retention(AnnotationRetention.SOURCE) internal annotation class KONSetterDsl | ||
|
||
/** Marks DSLs with no side effects that build entities */ | ||
@DslMarker @Retention(AnnotationRetention.SOURCE) public annotation class KONBuilderDsl | ||
@DslMarker @Retention(AnnotationRetention.SOURCE) internal annotation class KONBuilderDsl |
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
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
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
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
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