Class: SharedBroker::SchemaRegistry::Providers::Local
- Inherits:
-
Object
- Object
- SharedBroker::SchemaRegistry::Providers::Local
- Defined in:
- lib/shared_broker/schema_registry/providers/local.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ Local
constructor
A new instance of Local.
- #register(topic, schema) ⇒ Object
- #validate!(topic, payload) ⇒ Object
Constructor Details
#initialize ⇒ Local
Returns a new instance of Local.
9 10 11 |
# File 'lib/shared_broker/schema_registry/providers/local.rb', line 9 def initialize @schemas = {} end |
Instance Method Details
#clear ⇒ Object
32 33 34 |
# File 'lib/shared_broker/schema_registry/providers/local.rb', line 32 def clear @schemas.clear end |
#register(topic, schema) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/shared_broker/schema_registry/providers/local.rb', line 13 def register(topic, schema) unless schema.respond_to?(:call) raise ArgumentError, "Expected schema to respond to :call, got #{schema.class} with value #{schema.inspect}. Expected shape: respond_to?(:call)" end @schemas[topic.to_s] = schema end |
#validate!(topic, payload) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/shared_broker/schema_registry/providers/local.rb', line 21 def validate!(topic, payload) schema = @schemas[topic.to_s] return unless schema result = schema.call(payload) return if result.success? raise SharedBroker::Validation::ValidationError, "Schema validation failed for topic #{topic.inspect}. Expected keys: #{schema.rules.keys.inspect}, got payload: #{payload.inspect}. Errors: #{result.errors.to_h.inspect}" end |