Class: Avro::Schema::UnionSchema
- Inherits:
-
Avro::Schema
- Object
- Avro::Schema
- Avro::Schema::UnionSchema
- 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
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
Attributes inherited from Avro::Schema
Instance Method Summary collapse
-
#initialize(schemas, names = nil, default_namespace = nil) ⇒ UnionSchema
constructor
A new instance of UnionSchema.
- #to_avro(names = Set.new) ⇒ Object
Methods inherited from Avro::Schema
#==, #be_read?, #hash, #md5_fingerprint, #mutual_read?, parse, #read?, 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.
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/avro/schema.rb', line 318 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.
316 317 318 |
# File 'lib/avro/schema.rb', line 316 def schemas @schemas end |
Instance Method Details
#to_avro(names = Set.new) ⇒ Object
337 338 339 |
# File 'lib/avro/schema.rb', line 337 def to_avro(names=Set.new) schemas.map {|schema| schema.to_avro(names) } end |