diff --git a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt index b5a40513..6c920f57 100644 --- a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt +++ b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt @@ -4,14 +4,14 @@ import hep.dataforge.meta.* import hep.dataforge.names.toName -class DataFilter(override val config: Config) : Specification { +class DataFilter(override val config: Config) : Specific { var from by string() var to by string() var pattern by string("*.") // val prefix by string() // val suffix by string() - companion object : SpecificationCompanion { + companion object : Specification { override fun wrap(config: Config): DataFilter = DataFilter(config) } } diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/NodeDescriptor.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/NodeDescriptor.kt index bf09cf70..bbc9fdcc 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/NodeDescriptor.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/NodeDescriptor.kt @@ -31,7 +31,7 @@ import hep.dataforge.names.toName * * @author Alexander Nozik */ -class NodeDescriptor(override val config: Config) : Specification { +class NodeDescriptor(override val config: Config) : Specific { /** * The name of this node @@ -120,7 +120,7 @@ class NodeDescriptor(override val config: Config) : Specification { //override val descriptor: NodeDescriptor = empty("descriptor") - companion object : SpecificationCompanion { + companion object : Specification { override fun wrap(config: Config): NodeDescriptor = NodeDescriptor(config) diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/ValueDescriptor.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/ValueDescriptor.kt index 7f066e99..38b509e7 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/ValueDescriptor.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/ValueDescriptor.kt @@ -29,7 +29,7 @@ import hep.dataforge.values.ValueType * * @author Alexander Nozik */ -class ValueDescriptor(override val config: Config) : Specification { +class ValueDescriptor(override val config: Config) : Specific { /** * The default for this value. Null if there is no default. @@ -121,7 +121,7 @@ class ValueDescriptor(override val config: Config) : Specification { this.allowedValues = v.map { Value.of(it) } } - companion object : SpecificationCompanion { + companion object : Specification { override fun wrap(config: Config): ValueDescriptor = ValueDescriptor(config) diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt index 3f39b8bf..9a5a72c5 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt @@ -95,8 +95,8 @@ inline fun > Configurable.enum(default: E, key: String? = nu fun Configurable.node(key: String? = null) = MutableNodeDelegate(config, key) -fun Configurable.spec(spec: SpecificationCompanion, key: String? = null) = +fun Configurable.spec(spec: Specification, key: String? = null) = MutableMorphDelegate(config, key) { spec.wrap(it) } -fun Configurable.spec(builder: (Config) -> T, key: String? = null) = +fun Configurable.spec(builder: (Config) -> T, key: String? = null) = MutableMorphDelegate(config, key) { specification(builder).wrap(it) } \ No newline at end of file diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt index e1a56832..8182495b 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt @@ -118,7 +118,7 @@ operator fun > M.set(name: Name, value: Any?) { is MetaItem.NodeItem<*> -> setNode(name, value.node) } is Meta -> setNode(name, value) - is Specification -> setNode(name, value.config) + is Specific -> setNode(name, value.config) else -> setValue(name, Value.of(value)) } } diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specific.kt similarity index 59% rename from dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specific.kt index 72e6e4b6..10210fb4 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specific.kt @@ -3,16 +3,16 @@ package hep.dataforge.meta /** * Marker interface for specifications */ -interface Specification : Configurable { +interface Specific : Configurable { operator fun get(name: String): MetaItem? = config[name] } /** * Allows to apply custom configuration in a type safe way to simple untyped configuration. - * By convention [Specification] companion should inherit this class + * By convention [Specific] companion should inherit this class * */ -interface SpecificationCompanion { +interface Specification { /** * Update given configuration using given type as a builder */ @@ -32,31 +32,31 @@ interface SpecificationCompanion { fun wrap(meta: Meta): T = wrap(meta.toConfig()) } -fun specification(wrapper: (Config) -> T): SpecificationCompanion = - object : SpecificationCompanion { +fun specification(wrapper: (Config) -> T): Specification = + object : Specification { override fun wrap(config: Config): T = wrapper(config) } /** * Apply specified configuration to configurable */ -fun > T.configure(spec: S, action: C.() -> Unit) = +fun > T.configure(spec: S, action: C.() -> Unit) = apply { spec.update(config, action) } /** * Update configuration using given specification */ -fun > Specification.update(spec: S, action: C.() -> Unit) = +fun > Specific.update(spec: S, action: C.() -> Unit) = apply { spec.update(config, action) } /** * Create a style based on given specification */ -fun > S.createStyle(action: C.() -> Unit): Meta = +fun > S.createStyle(action: C.() -> Unit): Meta = Config().also { update(it, action) } -fun Specification.spec( - spec: SpecificationCompanion, +fun Specific.spec( + spec: Specification, key: String? = null ) = MutableMorphDelegate(config, key) { spec.wrap(it) } \ No newline at end of file diff --git a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt index 34cb43b6..64cc9ad3 100644 --- a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt +++ b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt @@ -13,13 +13,13 @@ class MetaDelegateTest { @Test fun delegateTest() { - class InnerSpec(override val config: Config) : Specification { + class InnerSpec(override val config: Config) : Specific { var innerValue by string() } val innerSpec = specification(::InnerSpec) - val testObject = object : Specification { + val testObject = object : Specific { override val config: Config = Config() var myValue by string() var safeValue by double(2.2)