Class: UniversalValidator::Validator
- Inherits:
-
Object
- Object
- UniversalValidator::Validator
- Defined in:
- lib/universal_validator/validator.rb
Instance Method Summary collapse
- #add_error_for(field, msg) ⇒ Object
- #errors ⇒ Object
- #errors? ⇒ Boolean
- #errors_for(field) ⇒ Object
-
#initialize {|_self| ... } ⇒ Validator
constructor
A new instance of Validator.
Constructor Details
#initialize {|_self| ... } ⇒ Validator
Returns a new instance of Validator.
22 23 24 |
# File 'lib/universal_validator/validator.rb', line 22 def initialize yield self if block_given? end |
Instance Method Details
#add_error_for(field, msg) ⇒ Object
34 35 36 37 |
# File 'lib/universal_validator/validator.rb', line 34 def add_error_for(field, msg) errors[field] ||= [] errors[field] << msg end |
#errors ⇒ Object
30 31 32 |
# File 'lib/universal_validator/validator.rb', line 30 def errors @errors ||= {} end |
#errors? ⇒ Boolean
26 27 28 |
# File 'lib/universal_validator/validator.rb', line 26 def errors? errors.count.positive? end |
#errors_for(field) ⇒ Object
39 40 41 |
# File 'lib/universal_validator/validator.rb', line 39 def errors_for(field) errors[field] end |