Skip to content

Instantly share code, notes, and snippets.

@timmc
Created November 18, 2018 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/a8c17046255ad8b4ac0923a6933de8ea to your computer and use it in GitHub Desktop.
Save timmc/a8c17046255ad8b4ac0923a6933de8ea to your computer and use it in GitHub Desktop.
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