Create days with examples without manually creating an input
This commit is contained in:
parent
55271e210d
commit
fecc1df668
@ -6,6 +6,7 @@ import io.micronaut.core.annotation.AnnotationMetadataDelegate
|
||||
import io.micronaut.core.annotation.AnnotationMetadataProvider
|
||||
import io.micronaut.core.annotation.AnnotationValue
|
||||
import io.micronaut.core.beans.BeanIntrospection
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
internal inline fun <reified T> getIntrospection(): BeanIntrospection<T> =
|
||||
@ -21,3 +22,15 @@ internal inline fun <reified T : Annotation> AnnotationMetadataProvider.hasAnnot
|
||||
findAnnotation(T::class.java).isPresent
|
||||
|
||||
inline fun <reified T> createDay() = BeanContext.run().getBean<T>()
|
||||
|
||||
// A custom resourceLoader that returns a string should be more appropriate but ¯\_(ツ)_/¯
|
||||
fun BeanContext.registerExampleLoader(example: String) {
|
||||
registerSingleton(TempFileResourceLoader(File.createTempFile("aoc-example", ".txt").apply {
|
||||
writeText(example)
|
||||
}))
|
||||
}
|
||||
|
||||
inline fun <reified T> createDay(example: String): T = BeanContext.build()
|
||||
.apply { registerExampleLoader(example) }
|
||||
.start()
|
||||
.getBean()
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package be.vandewalleh.aoc.utils.input
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import javax.inject.Singleton
|
||||
|
||||
@ -19,3 +20,7 @@ class ResourceLoaderImpl : ResourceLoader {
|
||||
return Path.of(url.toURI())
|
||||
}
|
||||
}
|
||||
|
||||
class TempFileResourceLoader(private val tempFile: File) : ResourceLoader {
|
||||
override fun ofDay(day: Int) = Path.of(tempFile.path)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user