-
-
Save Jacoby6000/66bde0e4aca05a6ca4dfaee5495a45ec to your computer and use it in GitHub Desktop.
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 IndexProcess private (config: Config) { | |
// e.g. | |
// index { | |
// entities { | |
// slide { | |
// products: {to: many, is: product} | |
// sites: {to: many, is: site} | |
// } | |
// site: { | |
// architects: {to: many, is: architect} | |
// engineers: {to: many, is: engineer} | |
// } | |
// product: {} | |
// architect: {} | |
// engineer: {} | |
// } | |
// } | |
val entities: Config = config.getConfig("entities") | |
// Flatten a configuration, extracting child objects. | |
// Config(...) => Seq(child1, child2, ...original - (child1..child2)) | |
def normalize(config: Config, as: String): List[Config] = { | |
config.root.keySet.asScala filter { key => | |
entities.hasPath(joinPath(as, key)) | |
} match { | |
case Map.empty => List.apply(config) | |
case relKeys => { | |
val parent: Config = relKeys.foldRight(config) { | |
(key, config) => config.withoutPath(key) | |
} | |
val children: List[Config] = relKeys.flatMap { | |
(key) => normalize( | |
config.getConfig(key), | |
entities.getString(joinPath(as, key, "is")) | |
) | |
}.toList | |
children :+ parent | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment