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:
parent
be8de7fbca
commit
d02ca3eebd
@ -72,16 +72,23 @@ public protocol Rule<ValueType> {
|
|||||||
func isValid(value: ValueType?) -> Bool
|
func isValid(value: ValueType?) -> Bool
|
||||||
/// Error Message to be show if the value is invalid.
|
/// Error Message to be show if the value is invalid.
|
||||||
var errorMessage: String { get }
|
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.
|
/// Type Erased Rule for a specific ValueType.
|
||||||
public struct AnyRule<ValueType>: Rule {
|
public struct AnyRule<ValueType>: Rule {
|
||||||
private let _isValid: (ValueType?) -> Bool
|
private let _isValid: (ValueType?) -> Bool
|
||||||
|
public var ruleType: String
|
||||||
public let errorMessage: String
|
public let errorMessage: String
|
||||||
|
|
||||||
public init<R: Rule>(_ rule: R) where R.ValueType == ValueType {
|
public init<R: Rule>(_ rule: R) where R.ValueType == ValueType {
|
||||||
self._isValid = rule.isValid
|
self._isValid = rule.isValid
|
||||||
|
self.ruleType = rule.ruleType
|
||||||
self.errorMessage = rule.errorMessage
|
self.errorMessage = rule.errorMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user