Class: RosettAi::Validators::SchemaValidator
- Inherits:
-
Object
- Object
- RosettAi::Validators::SchemaValidator
- Defined in:
- lib/rosett_ai/validators/schema_validator.rb
Overview
Generic JSON Schema validator for YAML configuration files.
Subclasses specify which schema to use by passing the schema filename to the constructor. The schema is loaded from conf/schemas/ relative to the project root.
API: valid?(file_path), validate(file_path), errors
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(schema:) ⇒ SchemaValidator
constructor
A new instance of SchemaValidator.
- #valid?(file_path) ⇒ Boolean
- #validate(file_path) ⇒ Object
Constructor Details
#initialize(schema:) ⇒ SchemaValidator
Returns a new instance of SchemaValidator.
22 23 24 25 26 |
# File 'lib/rosett_ai/validators/schema_validator.rb', line 22 def initialize(schema:) @schema_filename = schema @errors = [] @schemer = JSONSchemer.schema(load_schema) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
20 21 22 |
# File 'lib/rosett_ai/validators/schema_validator.rb', line 20 def errors @errors end |
Instance Method Details
#valid?(file_path) ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/rosett_ai/validators/schema_validator.rb', line 28 def valid?(file_path) @errors = [] content = load_file(file_path) return false unless content validate_schema(content) @errors.empty? end |
#validate(file_path) ⇒ Object
37 38 39 40 |
# File 'lib/rosett_ai/validators/schema_validator.rb', line 37 def validate(file_path) valid?(file_path) @errors end |