-
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
1 parent
f8df1c8
commit ea7e295
Showing
11 changed files
with
191 additions
and
24 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
29 changes: 29 additions & 0 deletions
29
...src/main/java/com/trendyol/transmission/transformer/request/execution/ExecutionBuilder.kt
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,29 @@ | ||
package com.trendyol.transmission.transformer.request.execution | ||
|
||
import com.trendyol.transmission.transformer.Transformer | ||
import com.trendyol.transmission.transformer.request.RequestHandler | ||
|
||
class ExecutionBuilder { | ||
|
||
fun buildWith( | ||
key: String, | ||
transformer: Transformer, | ||
execution: suspend RequestHandler.() -> Unit | ||
) { | ||
transformer.storage.registerExecution( | ||
key = key, | ||
delegate = ExecutionDelegate(execution) | ||
) | ||
} | ||
|
||
fun <A : Any> buildWith( | ||
key: String, | ||
transformer: Transformer, | ||
execution: suspend RequestHandler.(args: A) -> Unit | ||
) { | ||
transformer.storage.registerExecution( | ||
key = key, | ||
delegate = ExecutionDelegateWithArgs(execution) | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ain/java/com/trendyol/transmission/transformer/request/execution/ExecutionDelegateImpl.kt
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,21 @@ | ||
package com.trendyol.transmission.transformer.request.execution | ||
|
||
import com.trendyol.transmission.transformer.request.RequestHandler | ||
|
||
internal class ExecutionDelegate( | ||
private val execution: suspend RequestHandler.() -> Unit, | ||
) : ExecutionOwner.Default { | ||
|
||
override suspend fun execute(scope: RequestHandler) { | ||
execution.invoke(scope) | ||
} | ||
} | ||
|
||
internal class ExecutionDelegateWithArgs<A : Any>( | ||
private val execution: suspend RequestHandler.(args: A) -> Unit, | ||
) : ExecutionOwner.WithArgs<A> { | ||
|
||
override suspend fun execute(scope: RequestHandler, args: A) { | ||
execution(scope, args) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ion/src/main/java/com/trendyol/transmission/transformer/request/execution/ExecutionExt.kt
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,37 @@ | ||
package com.trendyol.transmission.transformer.request.execution | ||
|
||
import com.trendyol.transmission.Transmission | ||
import com.trendyol.transmission.transformer.Transformer | ||
import com.trendyol.transmission.transformer.request.Contract | ||
import com.trendyol.transmission.transformer.request.RequestHandler | ||
|
||
/** | ||
* Throws [IllegalArgumentException] when multiple executions with the same key | ||
* are defined inside the [Transformer]. | ||
* | ||
* Adds a execution to [Transformer] to be queried that returns Unit. | ||
* Can be queried using [RequestHandler.execute] | ||
* @param execution execution to get the result [Transmission.Data] | ||
*/ | ||
fun <C : Contract.Execution> Transformer.registerExecution( | ||
contract: C, | ||
execution: suspend RequestHandler.() -> Unit, | ||
) { | ||
ExecutionBuilder().buildWith(contract.key, this, execution) | ||
} | ||
|
||
/** | ||
* Throws [IllegalArgumentException] when multiple executions with the same key | ||
* are defined inside the [Transformer]. | ||
* | ||
* Adds a execution to [Transformer] to be queried. This execution accepts any class as Argument | ||
* that returns Unit. | ||
* Can be queried using [RequestHandler.execute] | ||
* @param execution execution to get the result [Transmission.Data] | ||
*/ | ||
fun <C : Contract.ExecutionWithArgs<A>, A : Any> Transformer.registerExecution( | ||
contract: C, | ||
execution: suspend RequestHandler.(args: A) -> Unit, | ||
) { | ||
ExecutionBuilder().buildWith(contract.key, this, execution) | ||
} |
14 changes: 14 additions & 0 deletions
14
...n/src/main/java/com/trendyol/transmission/transformer/request/execution/ExecutionOwner.kt
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,14 @@ | ||
package com.trendyol.transmission.transformer.request.execution | ||
|
||
import com.trendyol.transmission.transformer.request.RequestHandler | ||
|
||
internal sealed interface ExecutionOwner { | ||
|
||
interface WithArgs<A : Any> : ExecutionOwner { | ||
suspend fun execute(scope: RequestHandler, args: A) | ||
} | ||
|
||
interface Default : ExecutionOwner { | ||
suspend fun execute(scope: RequestHandler) | ||
} | ||
} |