Skip to content

Commit 5b60ff4

Browse files
committed
implements runByBuilder & dslMarker for explicit receiver and hightlighting
1 parent 0c206df commit 5b60ff4

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ An easy way to persistence and run block codes only as many times as necessary o
2424
And add a dependency code to your **module**'s `build.gradle` file.
2525
```gradle
2626
dependencies {
27-
implementation "com.github.skydoves:only:1.0.0"
27+
implementation "com.github.skydoves:only:1.0.1"
2828
}
2929
```
3030

dependencies.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ext.versions = [
22
minSdk : 15,
33
compileSdk : 29,
4-
versionCode : 1,
5-
versionName : '1.0.0',
4+
versionCode : 2,
5+
versionName : '1.0.1',
66

77
gradleBuildTool : '3.4.1',
88
spotlessGradle : '3.22.0',

only/src/main/java/com/skydoves/only/Only.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,26 @@ import androidx.annotation.VisibleForTesting
2727
annotation class OnlyDsl
2828

2929
/** Run [Only] by [Only.Builder] using kotlin dsl. */
30+
@OnlyDsl
3031
fun only(name: String, times: Int, block: Only.Builder.() -> Unit): Unit =
3132
Only.Builder(name, times).apply(block).run()
3233

3334
/** Run only once [Only] by [Only.Builder] using kotlin dsl. */
35+
@OnlyDsl
3436
fun onlyOnce(name: String, times: Int = 1, block: Only.Builder.() -> Unit): Unit =
3537
Only.Builder(name, times).apply(block).run()
3638

3739
/** Run only twice [Only] by [Only.Builder] using kotlin dsl. */
40+
@OnlyDsl
3841
fun onlyTwice(name: String, times: Int = 2, block: Only.Builder.() -> Unit): Unit =
3942
Only.Builder(name, times).apply(block).run()
4043

4144
/** Run only thrice [Only] by [Only.Builder] using kotlin dsl. */
45+
@OnlyDsl
4246
fun onlyThrice(name: String, times: Int = 3, block: Only.Builder.() -> Unit): Unit =
4347
Only.Builder(name, times).apply(block).run()
4448

4549
/** Easy way to run block codes only as many times as necessary. */
46-
@OnlyDsl
4750
object Only {
4851

4952
@JvmStatic
@@ -70,6 +73,11 @@ object Only {
7073
return this@Only
7174
}
7275

76+
/** run onDo using [Only.Builder]. */
77+
private fun runByBuilder(builder: Builder) {
78+
onDo(builder.name, builder.times, builder.onDo, builder.onDone, builder.version)
79+
}
80+
7381
/** check debugging mode. */
7482
fun onlyOnDoDebugMode(ignore: Boolean): Only {
7583
this.doOnDebugMode = ignore
@@ -238,9 +246,10 @@ object Only {
238246
}
239247

240248
/** Builder class for creating [Only]. */
249+
@OnlyDsl
241250
class Builder(
242-
private val name: String,
243-
private val times: Int = 1
251+
val name: String,
252+
val times: Int = 1
244253
) {
245254

246255
@JvmField
@@ -255,7 +264,7 @@ object Only {
255264
fun version(version: String): Builder = apply { this.version = version }
256265

257266
fun run() {
258-
onDo(name, times, onDo, onDone, version)
267+
Only.runByBuilder(this@Builder)
259268
}
260269
}
261270
}

0 commit comments

Comments
 (0)