Skip to content

Commit

Permalink
Added enum mapping documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoppier committed Jun 15, 2024
1 parent 9638eb2 commit 860e8e8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
20 changes: 20 additions & 0 deletions website/src/_data/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
"caption": "Introduction",
"url": "/getting-started/introduction/",
"external": false
},
{
"caption": "Installation",
"url": "/getting-started/installation/",
"external": false
}
]
},
{
"title": "Usage",
"items": [
{
"caption": "Object Mapping",
"url": "/usage/object-mapping/",
"external": false
},
{
"caption": "Enum Mapping",
"url": "/usage/enum-mapping/",
"external": false
}
]
}
Expand Down
9 changes: 0 additions & 9 deletions website/src/posts/mapping/posts/enum-mapping.md

This file was deleted.

4 changes: 0 additions & 4 deletions website/src/posts/mapping/posts/posts.json

This file was deleted.

40 changes: 40 additions & 0 deletions website/src/posts/usage/posts/enum-mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: "Enum Mapping"
summary: "Performing enum mapping."
eleventyNavigation:
key: Enum Mapping
parent: Usage
order: 2
---

# Summary
Mappie supports creating enum mappers via the base class `EnumMapper`.

Suppose we have an enum class `Color`
```kotlin
enum class Color { RED, GREEN, BLUE; }
```
and an enum class `Colour`
```kotlin
enum class Colour { RED, GREEN, GLUE; }
```
The entries of both are identical, so we do not have to declare any mapping explicitly
```kotlin
object ColorMapper : EnumMapper<Color, Colour>() {
override fun map(from: Color): Colour = mapping()
}
```

Now suppose `Color`{:.kotlin} has an extra entry: `Color.ORANGE`, whilst `Colour` does
not have `Colour.ORANGE`, but does have `Colour.OTHER`. We can map `Colour.ORANGE` to `Colour.OTHER` via

```kotlin
object ColorMapper : EnumMapper<Color, Colour>() {
override fun map(from: Color): Colour = mapping {
Colour.OTHER mappedFromEnumEntry Color.ORANGE
}
}
```

# Configuration options

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: "Object mapping"
title: "Object Mapping"
summary: "Performing object mapping."
eleventyNavigation:
key: ObjectMapping
parent: Mapping
key: Object Mapping
parent: Usage
order: 1
---

4 changes: 4 additions & 0 deletions website/src/posts/usage/posts/posts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"layout": "layouts/post.html",
"permalink": "/usage/{{ title | slug }}/index.html"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Mapping"
title: "Usage"
eleventyNavigation:
key: Mapping
key: Usage
order: 2
---

0 comments on commit 860e8e8

Please sign in to comment.