Method: Avro::Schema::UnionSchema#initialize
- Defined in:
- lib/avro/schema.rb
#initialize(schemas, names = nil, default_namespace = nil) ⇒ UnionSchema
Returns a new instance of UnionSchema.
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/avro/schema.rb', line 400 def initialize(schemas, names=nil, default_namespace=nil) super(:union) @schemas = schemas.each_with_object([]) do |schema, schema_objects| 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 end end |