Class: Canon::Validators::YamlValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- Canon::Validators::YamlValidator
- Defined in:
- lib/canon/validators/yaml_validator.rb
Overview
Validator for YAML input
Validates YAML input using Ruby’s YAML parser. Raises detailed ValidationError with position information when malformed YAML is detected.
Class Method Summary collapse
-
.validate!(input) ⇒ void
Validate YAML input.
Methods inherited from BaseValidator
Class Method Details
.validate!(input) ⇒ void
This method returns an undefined value.
Validate YAML input
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/canon/validators/yaml_validator.rb', line 21 def self.validate!(input) return if input.nil? return if input.is_a?(Hash) || input.is_a?(Array) # Already parsed return if input.strip.empty? YAML.safe_load(input, permitted_classes: [Symbol, Date, Time]) rescue Psych::SyntaxError => e location = extract_location(e) raise Canon::ValidationError.new( (e.), format: :yaml, line: location[:line], column: location[:column], details: extract_context(input, e), ) end |