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.



9
10
11
12
# File 'lib/avro/builder/schema_store.rb', line 9

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

Instance Method Details

#find(name, namespace = nil) ⇒ Object



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

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