Class: Avro::Builder::Types::UnionType
- Inherits:
-
ComplexType
- Object
- Type
- ComplexType
- Avro::Builder::Types::UnionType
- Includes:
- TypeReferencer
- Defined in:
- lib/avro/builder/types/union_type.rb
Constant Summary collapse
- NULL_TYPE =
'null'
Constants included from Avro::Builder::TypeFactory
Avro::Builder::TypeFactory::BUILTIN_TYPES, Avro::Builder::TypeFactory::COMPLEX_TYPES, Avro::Builder::TypeFactory::NAMED_TYPES
Constants included from DslAttributes
DslAttributes::ATTRIBUTE_NAMES
Instance Attribute Summary
Attributes inherited from Type
Class Method Summary collapse
-
.union_with_null(serialized) ⇒ Object
serialized will be an array of types.
Instance Method Summary collapse
- #logical_type=(value) ⇒ Object
-
#serialize(reference_state) ⇒ Object
Unions are serialized as an array of types.
- #to_h(reference_state) ⇒ Object
- #validate! ⇒ Object
Methods inherited from ComplexType
avro_type_name, #initialize, #namespace
Methods inherited from Type
#abstract?, #cache!, #configure_options, #dsl_method?, #dsl_respond_to?, #initialize, #namespace
Methods included from Metadata
attribute?, #method_missing, register, reset!, #respond_to_missing?
Methods included from DslAttributes
Methods included from DslOptions
Constructor Details
This class inherits a constructor from Avro::Builder::Types::ComplexType
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Avro::Builder::Metadata
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.
30 31 32 |
# File 'lib/avro/builder/types/union_type.rb', line 30 def self.union_with_null(serialized) serialized.reject { |type| type.to_s == NULL_TYPE }.unshift(:null) end |
Instance Method Details
#logical_type=(value) ⇒ Object
38 39 40 |
# File 'lib/avro/builder/types/union_type.rb', line 38 def logical_type=(value) raise AttributeError.new("Logical types are not supported for unions: #{value}.") end |
#serialize(reference_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(reference_state) types.map { |type| type.serialize(reference_state) } end |
#to_h(reference_state) ⇒ Object
24 25 26 |
# File 'lib/avro/builder/types/union_type.rb', line 24 def to_h(reference_state) serialize(reference_state) end |
#validate! ⇒ Object
34 35 36 |
# File 'lib/avro/builder/types/union_type.rb', line 34 def validate! validate_required_attribute!(:types) end |