Class: Canon::Validators::BaseValidator
- Inherits:
-
Object
- Object
- Canon::Validators::BaseValidator
- Defined in:
- lib/canon/validators/base_validator.rb
Overview
Base class for all input validators
This abstract base class defines the interface that all format-specific validators must implement. Each validator is responsible for validating input in a specific format and raising detailed ValidationError when issues are found.
Direct Known Subclasses
Class Method Summary collapse
-
.extract_location(error) ⇒ Hash
Extract line and column information from an error.
-
.validate!(input) ⇒ void
Validate input and raise ValidationError if invalid.
Class Method Details
.extract_location(error) ⇒ Hash
Extract line and column information from an error
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/canon/validators/base_validator.rb', line 28 def self.extract_location(error) line = nil column = nil # Try to extract line/column from error message if error.respond_to?(:line) line = error.line elsif error. =~ /line[:\s]+(\d+)/i line = ::Regexp.last_match(1).to_i end if error.respond_to?(:column) column = error.column elsif error. =~ /column[:\s]+(\d+)/i column = ::Regexp.last_match(1).to_i end { line: line, column: column } end |
.validate!(input) ⇒ void
This method returns an undefined value.
Validate input and raise ValidationError if invalid
19 20 21 22 |
# File 'lib/canon/validators/base_validator.rb', line 19 def self.validate!(input) raise NotImplementedError, "#{name} must implement validate! method" end |