validateRuleFor method

ValidationResult validateRuleFor (String key)

Validate all rules associated with the passed in key

Implementation

ValidationResult validateRuleFor(String key) {
  var result = new ValidationResult();
  if (_rules.containsKey(key)) {
    dynamic value = _rules[key].getter();
    //Iterate each ValidationRule and invoke its validate method
    _rules[key].rules.forEach((BaseValidator r) {
      //Accumulate validation failures in order to create a validation result.
      var isValid = r.isValid(value);
      if (!isValid) {
        result.errors.add(new ValidationFailure()
          ..associatedWith = key
          ..errorMessage = r.message);
      }
    });
  }
  //TODO: throw err if key not found

  return result;
}