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
CRC_EMPTY, DECIMAL_LOGICAL_TYPE, DEFAULT_VALIDATE_OPTIONS, INT_MAX_VALUE, INT_MIN_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE, NAMED_TYPES, NAMED_TYPES_SYM, NAME_REGEX, PRIMITIVE_TYPES, PRIMITIVE_TYPES_SYM, SINGLE_OBJECT_MAGIC_NUMBER, 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?, #crc_64_avro_fingerprint, #hash, #initFPTable, #md5_fingerprint, #mutual_read?, parse, #read?, real_parse, #sha256_fingerprint, #single_object_encoding_header, #single_object_schema_fingerprint, #subparse, #to_s, #type, #type_adapter, validate
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 |