Class: Avro::Schema::UnionSchema

Inherits:
Avro::Schema show all
Defined in:
lib/avro/schema.rb

Constant Summary

Constants inherited from Avro::Schema

INT_MAX_VALUE, INT_MIN_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE, NAMED_TYPES, NAMED_TYPES_SYM, PRIMITIVE_TYPES, PRIMITIVE_TYPES_SYM, VALID_TYPES, VALID_TYPES_SYM

Instance Attribute Summary collapse

Attributes inherited from Avro::Schema

#logical_type, #type_sym

Instance Method Summary collapse

Methods inherited from Avro::Schema

#==, #hash, #md5_fingerprint, parse, real_parse, #sha256_fingerprint, #subparse, #to_s, #type, #type_adapter, validate

Constructor Details

#initialize(schemas, names = nil, default_namespace = nil) ⇒ UnionSchema

Returns a new instance of UnionSchema.



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/avro/schema.rb', line 302

def initialize(schemas, names=nil, default_namespace=nil)
  super(:union)

  schema_objects = []
  schemas.each_with_index do |schema, i|
    new_schema = subparse(schema, names, default_namespace)
    ns_type = new_schema.type_sym

    if VALID_TYPES_SYM.include?(ns_type) &&
        !NAMED_TYPES_SYM.include?(ns_type) &&
        schema_objects.any?{|o| o.type_sym == ns_type }
      raise SchemaParseError, "#{ns_type} is already in Union"
    elsif ns_type == :union
      raise SchemaParseError, "Unions cannot contain other unions"
    else
      schema_objects << new_schema
    end
    @schemas = schema_objects
  end
end

Instance Attribute Details

#schemasObject (readonly)

Returns the value of attribute schemas.



300
301
302
# File 'lib/avro/schema.rb', line 300

def schemas
  @schemas
end

Instance Method Details

#to_avro(names = Set.new) ⇒ Object



323
324
325
# File 'lib/avro/schema.rb', line 323

def to_avro(names=Set.new)
  schemas.map {|schema| schema.to_avro(names) }
end