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.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Validator
constructor
:nodoc:.
-
#to_s ⇒ Object
Returns an error message listing validation errors (or
nilif there were none). - #validate(src, &blk) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Validator
:nodoc:
11 12 13 |
# File 'lib/assert_valid_content/validator.rb', line 11 def initialize( opts = {} ) #:nodoc: @src, @errors = nil, [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Validation errors
9 10 11 |
# File 'lib/assert_valid_content/validator.rb', line 9 def errors @errors end |
Instance Method Details
#to_s ⇒ Object
Returns an error message listing validation errors (or nil if there were none).
16 17 18 19 20 |
# File 'lib/assert_valid_content/validator.rb', line 16 def to_s return nil unless @errors "#{self.class.name} validation failed:\n" + @errors.map { |e| " #{e.to_s}" }.join("\n") end |
#validate(src, &blk) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/assert_valid_content/validator.rb', line 22 def validate( src, &blk ) @src = src content = case src when Pathname then IO.read src when IO then src.read else src end validate! content, &blk end |