@@ -157,31 +157,29 @@ extension UserAttribute {
157
157
return try value!. isLessOrEqual ( than: rawAttributeValue!, condition: stringRepresentation, name: nameFinal)
158
158
// semantic versioning seems unique. the comarison is to compare verion but the passed in version is the target version.
159
159
case . semver_eq:
160
- guard let targetValue = AttributeValue ( value: rawAttributeValue) else {
161
- throw OptimizelyError . evaluateAttributeInvalidCondition ( " attribute value \( nameFinal) invalid type " )
162
- }
160
+ let targetValue = try targetAsAttributeValue ( value: rawAttributeValue, attribute: value, nameFinal: nameFinal)
163
161
return try targetValue. isSemanticVersionEqual ( than: value!. stringValue)
164
162
case . semver_lt:
165
- guard let targetValue = AttributeValue ( value: rawAttributeValue) else {
166
- throw OptimizelyError . evaluateAttributeInvalidCondition ( " attribute value \( nameFinal) invalid type " )
167
- }
163
+ let targetValue = try targetAsAttributeValue ( value: rawAttributeValue, attribute: value, nameFinal: nameFinal)
168
164
return try targetValue. isSemanticVersionLess ( than: value!. stringValue)
169
165
case . semver_le:
170
- guard let targetValue = AttributeValue ( value: rawAttributeValue) else {
171
- throw OptimizelyError . evaluateAttributeInvalidCondition ( " attribute value \( nameFinal) invalid type " )
172
- }
166
+ let targetValue = try targetAsAttributeValue ( value: rawAttributeValue, attribute: value, nameFinal: nameFinal)
173
167
return try targetValue. isSemanticVersionLessOrEqual ( than: value!. stringValue)
174
168
case . semver_gt:
175
- guard let targetValue = AttributeValue ( value: rawAttributeValue) else {
176
- throw OptimizelyError . evaluateAttributeInvalidCondition ( " attribute value \( nameFinal) invalid type " )
177
- }
169
+ let targetValue = try targetAsAttributeValue ( value: rawAttributeValue, attribute: value, nameFinal: nameFinal)
178
170
return try targetValue. isSemanticVersionGreater ( than: value!. stringValue)
179
171
case . semver_ge:
180
- guard let targetValue = AttributeValue ( value: rawAttributeValue) else {
181
- throw OptimizelyError . evaluateAttributeInvalidCondition ( " attribute value \( nameFinal) invalid type " )
182
- }
172
+ let targetValue = try targetAsAttributeValue ( value: rawAttributeValue, attribute: value, nameFinal: nameFinal)
183
173
return try targetValue. isSemanticVersionGreaterOrEqual ( than: value!. stringValue)
184
174
}
185
175
}
186
176
177
+ private func targetAsAttributeValue( value: Any ? , attribute: AttributeValue ? , nameFinal: String ) throws -> AttributeValue {
178
+ guard let targetValue = AttributeValue ( value: value) , targetValue. isComparable ( with: attribute!) else {
179
+ throw OptimizelyError . evaluateAttributeInvalidCondition ( " attribute value \( nameFinal) invalid type " )
180
+ }
181
+
182
+ return targetValue
183
+ }
184
+
187
185
}
0 commit comments