Module: Async::Matrix::Schema
- Defined in:
- lib/async/matrix/schema.rb,
lib/async/matrix/schema/registry.rb,
lib/async/matrix/schema/validation_error.rb
Overview
Schema-driven validation for Matrix events using the official matrix-org/matrix-spec YAML schemas and the json_schemer gem.
Schemas are loaded lazily from data/matrix-spec/event-schemas/schema/ and cached for the process lifetime. This ensures validation is always up-to-date with the spec – just re-run ‘bin/fetch-matrix-schemas` to pull the latest.
# Look up a schema by event type
Async::Matrix::Schema["m.room.message"] # => JSONSchemer::Schema
# Validate an event hash
Async::Matrix::Schema.valid?(event_hash) # => true/false
Async::Matrix::Schema.validate(event_hash) # => [errors]
# List all known event types
Async::Matrix::Schema.event_types # => ["m.accepted_terms", "m.call.answer", ...]
Defined Under Namespace
Classes: Registry, ValidationError
Class Method Summary collapse
-
.[](event_type) ⇒ JSONSchemer::Schema?
Look up a schema by Matrix event type.
-
.content_properties(event_type) ⇒ Array<String>
Content properties defined by the schema for a given event type.
-
.event_types ⇒ Array<String>
All known base event types.
-
.parse(event_hash) ⇒ ApplicationService::Event
Parse a raw event hash into a schema-aware Event.
-
.size ⇒ Integer
Total schemas loaded (base + variants).
-
.valid?(event_hash) ⇒ Boolean
Boolean validation.
-
.validate(event_hash) ⇒ Array<Hash>
Validate an event hash against its schema.
-
.variant(event_type, subtype) ⇒ JSONSchemer::Schema?
Look up a variant schema.
-
.variant_types ⇒ Array<Array(String, String)>
All known variant types as [event_type, subtype] pairs.
Class Method Details
.[](event_type) ⇒ JSONSchemer::Schema?
Look up a schema by Matrix event type.
33 34 35 |
# File 'lib/async/matrix/schema.rb', line 33 def [](event_type) Registry.instance[event_type] end |
.content_properties(event_type) ⇒ Array<String>
Content properties defined by the schema for a given event type.
73 74 75 |
# File 'lib/async/matrix/schema.rb', line 73 def content_properties(event_type) Registry.instance.content_properties(event_type) end |
.event_types ⇒ Array<String>
All known base event types.
61 62 63 |
# File 'lib/async/matrix/schema.rb', line 61 def event_types Registry.instance.event_types end |
.parse(event_hash) ⇒ ApplicationService::Event
Parse a raw event hash into a schema-aware Event.
80 81 82 |
# File 'lib/async/matrix/schema.rb', line 80 def parse(event_hash) ApplicationService::Event.new(event_hash) end |
.size ⇒ Integer
Total schemas loaded (base + variants).
86 87 88 |
# File 'lib/async/matrix/schema.rb', line 86 def size Registry.instance.size end |
.valid?(event_hash) ⇒ Boolean
Boolean validation.
55 56 57 |
# File 'lib/async/matrix/schema.rb', line 55 def valid?(event_hash) Registry.instance.valid?(event_hash) end |
.validate(event_hash) ⇒ Array<Hash>
Validate an event hash against its schema.
48 49 50 |
# File 'lib/async/matrix/schema.rb', line 48 def validate(event_hash) Registry.instance.validate(event_hash) end |