Class: Avro::Builder::SchemaStore

Inherits:
Object
  • Object
show all
Defined in:
lib/avro/builder/schema_store.rb

Overview

This class implements a schema store that loads Avro::Builder DSL files and returns Avro::Schema objects. It implements the same API as AvroTurf::SchemaStore.

Instance Method Summary collapse

Constructor Details

#initialize(path: nil) ⇒ SchemaStore

Returns a new instance of SchemaStore.



7
8
9
10
# File 'lib/avro/builder/schema_store.rb', line 7

def initialize(path: nil)
  Avro::Builder.add_load_path(path) if path
  @schemas = {}
end

Instance Method Details

#find(name, namespace = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/avro/builder/schema_store.rb', line 12

def find(name, namespace = nil)
  fullname = Avro::Name.make_fullname(name, namespace)

  @schemas[fullname] ||= Avro::Builder::DSL.new { eval_file(fullname) }
    .as_schema.tap do |schema|
      if schema.respond_to?(:fullname) && schema.fullname != fullname
        raise SchemaError.new(schema.fullname, fullname)
      end
    end
end