Skip to content

Commit

Permalink
Config values saved filter
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Oct 27, 2022
1 parent c97920d commit 63036e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ open class ConfigExtension(val project: Project) {

val valuesSaved get() = get().valuesSaved

fun valuesSaved(propFilter: (Prop) -> Boolean) = get().valuesSaved(propFilter)

fun value(propName: String) = read().value(propName)

fun valueOrNull(propName: String) = read().valueOrNull(propName)
Expand Down
9 changes: 5 additions & 4 deletions plugin/src/main/kotlin/io/wttech/gradle/config/Definition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ open class Definition(val name: String, val project: Project) {
get() = props.associate { it.name to it.value() }.toSortedMap()
set(vs) { vs.forEach { (k, v) -> findProp(k)?.valueSet(v) } }

private var valueSaveFilter: Prop.() -> Boolean = { true }
private var valueSaveFilter: (Prop) -> Boolean = { true }

fun valueSaveFilter(predicate: Prop.() -> Boolean) {
fun valueSaveFilter(predicate: (Prop) -> Boolean) {
this.valueSaveFilter = predicate
}

val valuesSaved: Map<String, Any?>
get() = props.filter(valueSaveFilter).associate { it.name to it.valueSaved() }.toSortedMap()
val valuesSaved: Map<String, Any?> get() = valuesSaved(valueSaveFilter)

fun valuesSaved(propFilter: (Prop) -> Boolean) = props.filter(propFilter).associate { it.name to it.valueSaved() }.toSortedMap()

fun value(propName: String) = valueOrNull(propName)
?: throw ConfigException("Config '$name' prop '$propName' is null!")
Expand Down

0 comments on commit 63036e1

Please sign in to comment.