Class: Serialbench::YamlValidator
- Inherits:
-
Object
- Object
- Serialbench::YamlValidator
- Defined in:
- lib/serialbench/yaml_validator.rb
Overview
Validates YAML files against YAML Schema definitions
Constant Summary collapse
- SCHEMA_DIR =
File.join(__dir__, '..', '..', 'data', 'schemas')
Class Method Summary collapse
Class Method Details
.validate(file_path, schema_name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/serialbench/yaml_validator.rb', line 12 def validate(file_path, schema_name) unless File.exist?(file_path) raise ArgumentError, "File not found: #{file_path}" end data = YAML.load_file(file_path) schema_path = File.join(SCHEMA_DIR, "#{schema_name}.yml") unless File.exist?(schema_path) raise ArgumentError, "Schema not found: #{schema_path}" end schema = YAML.load_file(schema_path) # Validate without strict schema checking (allow additional properties) JSON::Validator.validate!(schema, data, strict: false) true rescue JSON::Schema::ValidationError => e puts "❌ Validation failed: #{e.}" false end |