class Avro::SchemaNormalization
Public Class Methods
new()
click to toggle source
# File lib/avro/schema_normalization.rb 24 def initialize 25 @processed_names = [] 26 end
to_parsing_form(schema)
click to toggle source
# File lib/avro/schema_normalization.rb 20 def self.to_parsing_form(schema) 21 new.to_parsing_form(schema) 22 end
Public Instance Methods
to_parsing_form(schema)
click to toggle source
# File lib/avro/schema_normalization.rb 28 def to_parsing_form(schema) 29 MultiJson.dump(normalize_schema(schema)) 30 end
Private Instance Methods
normalize_field(field)
click to toggle source
# File lib/avro/schema_normalization.rb 71 def normalize_field(field) 72 { 73 name: field.name, 74 type: normalize_schema(field.type) 75 } 76 end
normalize_named_type(schema, attributes = {})
click to toggle source
# File lib/avro/schema_normalization.rb 78 def normalize_named_type(schema, attributes = {}) 79 name = Name.make_fullname(schema.name, schema.namespace) 80 81 { name: name, type: schema.type_sym.to_s }.merge(attributes) 82 end
normalize_schema(schema)
click to toggle source
# File lib/avro/schema_normalization.rb 34 def normalize_schema(schema) 35 type = schema.type_sym.to_s 36 37 if Schema::NAMED_TYPES.include?(type) 38 if @processed_names.include?(schema.name) 39 return schema.name 40 else 41 @processed_names << schema.name 42 end 43 end 44 45 case type 46 when *Schema::PRIMITIVE_TYPES 47 type 48 when "record" 49 fields = schema.fields.map {|field| normalize_field(field) } 50 51 normalize_named_type(schema, fields: fields) 52 when "enum" 53 normalize_named_type(schema, symbols: schema.symbols) 54 when "fixed" 55 normalize_named_type(schema, size: schema.size) 56 when "array" 57 { type: type, items: normalize_schema(schema.items) } 58 when "map" 59 { type: type, values: normalize_schema(schema.values) } 60 when "union" 61 if schema.schemas.nil? 62 [] 63 else 64 schema.schemas.map {|s| normalize_schema(s) } 65 end 66 else 67 raise "unknown type #{type}" 68 end 69 end