-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.dart
31 lines (29 loc) · 1.16 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import 'package:eagleyeix/metric.dart';
import 'package:validomix/validomix.dart';
class SimpleMessageProducer implements VxMessageProducer<String, String> {
final String message;
SimpleMessageProducer(this.message);
@override
String produce(Map<String, String> options, String value) => message;
}
void main() {
final metricStoreHolder = ExMetricStoreHolder();
final optionsInventory = VxOptionsInventory();
final rule = VxStringRules.charsLessThan<String>(
name: 'test',
metricStoreHolder: metricStoreHolder,
optionsInventory: optionsInventory,
successProducers: [SimpleMessageProducer('Success')],
failureProducers: [SimpleMessageProducer('Too many characters')]);
final hello = rule.validate({'test#maxChars': "10"}, 'hello');
final wayTooLong = rule.validate({'test#maxChars': "10"},
'This is a long string that is more than 10 characters');
print('Hello: $hello');
// Hello: [Success]
print('Way Too Long: $wayTooLong');
// Way Too Long: [Too many characters]
for (var inventory in optionsInventory.toList()) {
print("${inventory.name}->${inventory.descriptors}");
// test#maxChars->[integer, positive]
}
}