Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 307cae9

Browse files
authored
Merge pull request #22 from k163377/add_dummy_constructor
Add dummy constructor.
2 parents 0c9883d + 5a5d325 commit 307cae9

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

README.ja.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ data class Dst(...)
126126
val mapper: KRowMapper<Dst> = KRowMapper(Dst::class)
127127
```
128128

129+
ダミーコンストラクタを用いることで以下のようにも書けます。
130+
131+
```kotlin
132+
val mapper: KRowMapper<Dst> = KRowMapper<Dst>()
133+
```
134+
129135
#### KConstructorアノテーションによる呼び出し対象指定
130136
`KClass`から初期化を行う場合、`KConstructor`アノテーションを用いて呼び出し対象の関数を指定することができます。
131137

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ data class Dst(...)
131131
val mapper: KRowMapper<Dst> = KRowMapper(Dst::class)
132132
```
133133

134+
135+
You can also write the following using a `dummy constructor`.
136+
137+
```kotlin
138+
val mapper: KRowMapper<Dst> = KRowMapper<Dst>()
139+
```
140+
134141
#### Specifying the target of a call by KConstructor annotation
135142
When you initialize from the `KClass`, you can use the `KConstructor` annotation and to specify the function to be called.
136143

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.mapk.krowmapper
2+
3+
import com.mapk.krowmapper.KRowMapper as Mapper
4+
5+
@Suppress("FunctionName")
6+
inline fun <reified T : Any> KRowMapper(
7+
noinline parameterNameConverter: ((String) -> String)? = null
8+
) = Mapper(T::class, parameterNameConverter)

src/test/kotlin/com/mapk/krowmapper/DefaultValueTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DefaultValueTest {
2222
every { resultSet.getObject("foo_id", any<Class<*>>()) } returns 1
2323
every { resultSet.getObject("bar_value", any<Class<*>>()) } returns "From result set."
2424

25-
val result = KRowMapper(::Dst, this::camelToSnake).mapRow(resultSet, 0)
25+
val result = KRowMapper(Dst::class, this::camelToSnake).mapRow(resultSet, 0)
2626

2727
Assertions.assertEquals(1, result.fooId)
2828
Assertions.assertEquals("default", result.barValue)

src/test/kotlin/com/mapk/krowmapper/KParameterFlattenTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class KParameterFlattenTest {
3333
every { getObject("qux_qux", any<Class<*>>()) } returns LocalDateTime.MIN
3434
}
3535

36-
val result = KRowMapper(::Dst, this::camelToSnake).mapRow(resultSet, 0)
36+
val result = KRowMapper<Dst>(this::camelToSnake).mapRow(resultSet, 0)
3737
assertEquals(expected, result)
3838

3939
verify(exactly = 1) { resultSet.getObject("baz_baz_foo_foo", Integer::class.java) }

0 commit comments

Comments
 (0)