Class: AvroPinions::SchemaRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/avro_pinions/schema_registry.rb

Direct Known Subclasses

FileRegistry

Instance Method Summary collapse

Constructor Details

#initializeSchemaRegistry

Returns a new instance of SchemaRegistry.



3
4
5
# File 'lib/avro_pinions/schema_registry.rb', line 3

def initialize
  @cache = {}
end

Instance Method Details

#canonical_name(schema_name, namespace = "") ⇒ Object



13
14
15
16
17
18
19
# File 'lib/avro_pinions/schema_registry.rb', line 13

def canonical_name(schema_name, namespace = "")
  if namespace.length > 0
    "#{namespace}.#{schema_name}"
  else
    schema_name
  end
end

#load_schema(schema_name, namespace) ⇒ Object



21
22
23
# File 'lib/avro_pinions/schema_registry.rb', line 21

def load_schema(schema_name, namespace)
  raise AvroPinions::NotFullyImplementedError.new("Please define how to load schemas")
end

#schema(schema_name, namespace = "") ⇒ Object



7
8
9
10
11
# File 'lib/avro_pinions/schema_registry.rb', line 7

def schema(schema_name, namespace = "")
  with_cache(schema_name, namespace) do
    load_schema(schema_name, namespace)
  end
end

#with_cache(schema_name, namespace, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/avro_pinions/schema_registry.rb', line 25

def with_cache(schema_name, namespace, &block)
  key = canonical_name(schema_name, namespace)

  unless @cache.has_key?(key)
    @cache[key] = block.call
  end

  @cache[key]
end