Class: AssertValidContent::Validator
- Inherits:
-
Object
- Object
- AssertValidContent::Validator
- Defined in:
- lib/assert_valid_content/validator.rb
Overview
Base class for all content validators
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Validation errors.
Class Method Summary collapse
-
.validates(type) ⇒ Object
Register a derived class as a validator for content of type
type.
Instance Method Summary collapse
-
#initialize ⇒ Validator
constructor
:nodoc:.
-
#to_s ⇒ Object
Returns an error message listing validation errors (or
nilif there were none).
Constructor Details
#initialize ⇒ Validator
:nodoc:
39 40 41 |
# File 'lib/assert_valid_content/validator.rb', line 39 def initialize #:nodoc: @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Validation errors
37 38 39 |
# File 'lib/assert_valid_content/validator.rb', line 37 def errors @errors end |
Class Method Details
.validates(type) ⇒ Object
Register a derived class as a validator for content of type type
51 52 53 |
# File 'lib/assert_valid_content/validator.rb', line 51 def self.validates( type ) AssertValidContent.validators[type] << self end |
Instance Method Details
#to_s ⇒ Object
Returns an error message listing validation errors (or nil if there were none).
44 45 46 47 |
# File 'lib/assert_valid_content/validator.rb', line 44 def to_s return nil unless @errors "#{self.class.name} validation failed:\n" + @errors.map { |e| " #{e.to_s}" }.join("\n") end |