class Avro::Schema::UnionSchema

Attributes

schemas[R]

Public Class Methods

new(schemas, names=nil, default_namespace=nil) click to toggle source
Calls superclass method Avro::Schema::new
    # File lib/avro/schema.rb
401 def initialize(schemas, names=nil, default_namespace=nil)
402   super(:union)
403 
404   @schemas = schemas.each_with_object([]) do |schema, schema_objects|
405     new_schema = subparse(schema, names, default_namespace)
406     ns_type = new_schema.type_sym
407 
408     if VALID_TYPES_SYM.include?(ns_type) &&
409         !NAMED_TYPES_SYM.include?(ns_type) &&
410         schema_objects.any?{|o| o.type_sym == ns_type }
411       raise SchemaParseError, "#{ns_type} is already in Union"
412     elsif ns_type == :union
413       raise SchemaParseError, "Unions cannot contain other unions"
414     else
415       schema_objects << new_schema
416     end
417   end
418 end

Public Instance Methods

to_avro(names=Set.new) click to toggle source
    # File lib/avro/schema.rb
420 def to_avro(names=Set.new)
421   schemas.map {|schema| schema.to_avro(names) }
422 end