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

Inherits:
Type
  • Object
show all
Includes:
ComplexType, 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, Avro::Builder::TypeFactory::NAMED_TYPES

Instance Attribute Summary

Attributes inherited from Type

#avro_type_name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ComplexType

included, #initialize, #namespace, #to_h

Methods inherited from Type

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

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.


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

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

Instance Method Details

#logical_type=(value) ⇒ Object

Raises:


33
34
35
# File 'lib/avro/builder/types/union_type.rb', line 33

def logical_type=(value)
  raise AttributeError.new("Logical types are not supported for unions: #{value}.")
end

#serialize(referenced_state) ⇒ Object

Unions are serialized as an array of types


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

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

#validate!Object


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

def validate!
  validate_required_attribute!(:types)
end