Created
November 18, 2018 20:44
-
-
Save timmc/a8c17046255ad8b4ac0923a6933de8ea to your computer and use it in GitHub Desktop.
Wanted: Fluent interface for specifying filesystem layout
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 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ended up writing it myself: