added ruleType so outside sources can know the type for this rule

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-07-30 11:06:03 -05:00
parent be8de7fbca
commit d02ca3eebd

View File

@ -72,16 +72,23 @@ public protocol Rule<ValueType> {
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<ValueType>: Rule {
private let _isValid: (ValueType?) -> Bool
public var ruleType: String
public let errorMessage: String
public init<R: Rule>(_ rule: R) where R.ValueType == ValueType {
self._isValid = rule.isValid
self.ruleType = rule.ruleType
self.errorMessage = rule.errorMessage
}