Class: SharedBroker::SchemaRegistry::Providers::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/shared_broker/schema_registry/providers/local.rb

Instance Method Summary collapse

Constructor Details

#initializeLocal

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

#clearObject



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