Skip to content

Instantly share code, notes, and snippets.

@timmc timmc/layout.kt
Created Nov 18, 2018

Embed
What would you like to do?
Wanted: Fluent interface for specifying filesystem layout
class Repo : Layout() {
val config by leaf("config.json")
val myKeyring by leaf("self.keyring")
val posts by dir("posts", ::PostsDir)
}
class PostsDir : Layout() {
val post by multiple().dir(name = """[0-9]+""".toRegex(), ::OnePost)
}
class OnePost : Layout() {
val metadata by leaf("metadata.json")
val contents by dir("contents", ::PostContents)
}
class PostContents : Layout() {
val attachment by multiple().leaf() // arbitrary names
}
To be accessed like this:
repo.posts.post(5).contents.attachment() -- produce list of all attachments
You can’t perform that action at this time.