From d02ca3eebd0ba0f99a7d9ea89e02733c1cc9b86b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 30 Jul 2024 11:06:03 -0500 Subject: [PATCH] added ruleType so outside sources can know the type for this rule Signed-off-by: Matt Bruce --- VDS/Protocols/FormFieldable.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/VDS/Protocols/FormFieldable.swift b/VDS/Protocols/FormFieldable.swift index 82666772..e5e6894c 100644 --- a/VDS/Protocols/FormFieldable.swift +++ b/VDS/Protocols/FormFieldable.swift @@ -72,16 +72,23 @@ public protocol Rule { func isValid(value: ValueType?) -> Bool /// Error Message to be show if the value is invalid. var errorMessage: String { get } + /// type of rule + var ruleType: String { get } +} + +extension Rule { + public var ruleType: String { "\(Self.self)" } } /// Type Erased Rule for a specific ValueType. public struct AnyRule: Rule { private let _isValid: (ValueType?) -> Bool - + public var ruleType: String public let errorMessage: String public init(_ rule: R) where R.ValueType == ValueType { self._isValid = rule.isValid + self.ruleType = rule.ruleType self.errorMessage = rule.errorMessage }