Class: Avro::Builder::Types::UnionType

Inherits:
Type
  • Object
show all
Includes:
ComplexType, ConfigurableType, TypeReferencer
Defined in:
lib/avro/builder/types/union_type.rb

Constant Summary collapse

NULL_TYPE =
'null'.freeze

Constants included from Avro::Builder::TypeFactory

Avro::Builder::TypeFactory::BUILTIN_TYPES, Avro::Builder::TypeFactory::COMPLEX_TYPES

Instance Attribute Summary

Attributes inherited from Type

#type_name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TypeReferencer

#create_builtin_or_lookup_named_type

Methods included from ConfigurableType

#configure_options

Methods included from ComplexType

included, #initialize, #namespace

Methods inherited from Type

#cache!, #configure_options, #dsl_method?, #dsl_respond_to?, #initialize, #namespace

Methods included from DslAttributes

#dsl_attribute?, included

Methods included from DslOptions

#dsl_option?, included

Class Method Details

.union_with_null(serialized) ⇒ Object

serialized will be an array of types. If the array includes :null then it is moved to the beginning of the array.



26
27
28
# File 'lib/avro/builder/types/union_type.rb', line 26

def self.union_with_null(serialized)
  serialized.reject { |type| type.to_s == NULL_TYPE }.unshift(:null)
end

Instance Method Details

#serialize(referenced_state) ⇒ Object

Unions are serialized as an array of types



20
21
22
# File 'lib/avro/builder/types/union_type.rb', line 20

def serialize(referenced_state)
  types.map { |type| type.serialize(referenced_state) }
end

#validate!Object



30
31
32
# File 'lib/avro/builder/types/union_type.rb', line 30

def validate!
  validate_required_attribute!(:types)
end