handle method

  1. @override
void handle(
  1. GuardContext<ErrorReporter> ctx,
  2. PropertyContext property
)
override

Implementation

@override
void handle(GuardContext ctx, PropertyContext property) {
  if (property.value == null) {
    return;
  }

  final values = source.where((element) => element.value == property.value);
  if (values.firstOrNull == null) {
    final str =
        message ??
        'The value must match one of the expected enum values ${source.map((e) => e.value).toList()}';
    final error = ctx.errorReporter.format('enum', property, str, {});

    ctx.errorReporter.report('enum', property.name, error);
    return;
  }

  property.mutate(values.firstOrNull);
}