Class: Avro::Schema::UnionSchema
- Inherits:
-
Schema
- Object
- Schema
- Avro::Schema::UnionSchema
- Defined in:
- lib/avro/schema.rb
Instance Attribute Summary collapse
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
Instance Method Summary collapse
-
#initialize(schemas, names = nil, default_namespace = nil) ⇒ UnionSchema
constructor
A new instance of UnionSchema.
- #to_avro(names = Set.new) ⇒ Object
Constructor Details
#initialize(schemas, names = nil, default_namespace = nil) ⇒ UnionSchema
Returns a new instance of UnionSchema.
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/avro/schema.rb', line 401 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 |
Instance Attribute Details
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
399 400 401 |
# File 'lib/avro/schema.rb', line 399 def schemas @schemas end |
Instance Method Details
#to_avro(names = Set.new) ⇒ Object
420 421 422 |
# File 'lib/avro/schema.rb', line 420 def to_avro(names=Set.new) schemas.map {|schema| schema.to_avro(names) } end |