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

#type_sym

Instance Method Summary collapse

Methods inherited from Avro::Schema

#==, #hash, parse, real_parse, #subparse, #to_s, #type, validate

Constructor Details

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

Returns a new instance of UnionSchema.



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/avro/schema.rb', line 274

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.



272
273
274
# File 'lib/avro/schema.rb', line 272

def schemas
  @schemas
end

Instance Method Details

#to_avro(names = Set.new) ⇒ Object



295
296
297
# File 'lib/avro/schema.rb', line 295

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