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
fun <T> Iterable<T>.foreach(action: T.() -> Unit) { | |
for (element in this) element.action() | |
} |
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
listOf(42).foreach { inc() } |
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
class Log { | |
var level: Level = Level.DEBUG | |
var tag: String? = null | |
var throwable: Throwable? = null | |
var message: String? = null | |
} |
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
inline fun tag(crossinline tag: () -> String) { | |
this.tag = tag.invoke() | |
} | |
inline fun throwable(crossinline throwable: () -> Throwable) { | |
this.throwable = throwable.invoke() | |
} | |
inline fun level(crossinline level: () -> Level) { | |
this.level = level.invoke() |
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
inline fun info(crossinline message: () -> String?) { | |
level { Level.INFO } | |
this.message = message.invoke() | |
} |
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
object Logger { | |
@JvmStatic | |
inline fun log(crossinline configure: Log.() -> Unit) { | |
if (isWritersAvailable) { | |
Log().let { | |
configure(it) | |
write(it) | |
} | |
} |
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
log { | |
level { WARNING } | |
tag { "MainActivity" } | |
message { "Something went wrong" } | |
} | |
log { | |
throwable { | |
UnsupportedOperationException() | |
} |
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
@Test | |
fun `test scenario dsl example`() = scenario { | |
var socket: WebSocket? = null | |
define { | |
`return mock socket when call factory`() | |
} | |
act { | |
socket = mockWebSocketFactory.invoke() | |
`do something important`() | |
} |
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
repositories { | |
jcenter() | |
} | |
dependencies { | |
compile "dmax.dsl:logger:0.1" | |
compile "dmax.dsl:logger-android:0.1@aar" | |
compile "dmax.dsl:logger-slf4j:0.1" | |
} |
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
<dependency> | |
<groupId>dmax.dsl</groupId> | |
<artifactId>logger</artifactId> | |
<version>0.1</version> | |
</dependency> | |
<dependency> | |
<groupId>dmax.dsl</groupId> | |
<artifactId>logger-android</artifactId> | |
<version>0.1</version> |