1 /* 2 * Hunt - A data validation for DLang based on hunt library. 3 * 4 * Copyright (C) 2015-2019, HuntLabs 5 * 6 * Website: https://www.huntlabs.net 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 module hunt.validation.Validator; 12 13 14 interface Validator { 15 16 /** 17 * <p> 18 * get error msg 19 * <p> 20 * The default implementation is a no-op. 21 * 22 */ 23 string getMessage(); 24 25 /** 26 * @return {@code false} if {@code value} does not pass the constraint 27 */ 28 bool isValid(); 29 30 /** 31 * set valid property name 32 */ 33 void setPropertyName(string name); 34 35 /** 36 * get valid property name 37 */ 38 string getPropertyName(); 39 } 40 41 class AbstractValidator : Validator { 42 43 protected bool _isValid = true; 44 protected string _propertyName ; 45 46 /** 47 * <p> 48 * get error msg 49 * <p> 50 * The default implementation is a no-op. 51 * 52 */ 53 override string getMessage(){ return string.init; } 54 55 /** 56 * @return {@code false} if {@code value} does not pass the constraint 57 */ 58 override protected bool isValid(){ return _isValid ;} 59 60 /** 61 * set valid property name 62 */ 63 void setPropertyName(string name) { _propertyName = name ;} 64 65 /** 66 * get valid property name 67 */ 68 string getPropertyName(){ return _propertyName; } 69 }