class AvroPinions::FileRegistry
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# File lib/avro_pinions/schema_registries/file_registry.rb, line 7 def initialize(options = {}) super() @path = options[:schema_path] or raise AvroPinions::ConfigurationError.new("please define the path to load schemas from") end
Public Instance Methods
file_path(schema_name, namespace)
click to toggle source
# File lib/avro_pinions/schema_registries/file_registry.rb, line 18 def file_path(schema_name, namespace) schema_file = "#{schema_name}.avsc" boring_filename = File.join(@path, schema_file) if File.exists?(boring_filename) boring_filename else fancy_filename = File.join(@path, *namespace.split(/\./), schema_file) if File.exists?(fancy_filename) fancy_filename else raise "File not found for namespace #{namespace} and schema #{schema_name}. Tried #{fancy_filename} and #{boring_filename}" end end end
load_schema(schema_name, namespace)
click to toggle source
# File lib/avro_pinions/schema_registries/file_registry.rb, line 12 def load_schema(schema_name, namespace) data = File.read(file_path(schema_name, namespace)) json = JSON.parse(data) Avro::Schema.real_parse(json) end