Module: SnippetCli::FileValidator
- Defined in:
- lib/snippet_cli/file_validator.rb
Overview
Validates a full Espanso match file (matches array + global_vars + imports + anchors) against the vendored merged schema (official + custom extensions).
Class Method Summary collapse
-
.errors(data) ⇒ Object
Returns an array of human-readable error strings with field pointers.
-
.errors_structured(data) ⇒ Object
Returns an array of structured error hashes: { pointer: String, message: String }.
-
.valid?(data) ⇒ Boolean
Returns true if the data hash is valid against the matchfile schema.
Class Method Details
.errors(data) ⇒ Object
Returns an array of human-readable error strings with field pointers. Empty array means the data is valid.
17 18 19 20 21 |
# File 'lib/snippet_cli/file_validator.rb', line 17 def self.errors(data) errors_structured(data).map do |e| e[:pointer].empty? ? e[:message] : "at #{e[:pointer]}: #{e[:message]}" end end |
.errors_structured(data) ⇒ Object
Returns an array of structured error hashes: { pointer: String, message: String }. Empty array means the data is valid.
25 26 27 28 29 30 31 |
# File 'lib/snippet_cli/file_validator.rb', line 25 def self.errors_structured(data) SchemaValidator.validate(HashUtils.stringify_keys_deep(data)).map do |error| pointer = error['data_pointer'].to_s = error['error'] || error.fetch('type', 'validation error') { pointer: pointer, message: } end end |
.valid?(data) ⇒ Boolean
Returns true if the data hash is valid against the matchfile schema.
11 12 13 |
# File 'lib/snippet_cli/file_validator.rb', line 11 def self.valid?(data) SchemaValidator.valid?(HashUtils.stringify_keys_deep(data)) end |