Class: Icss::UnionType

Inherits:
EnumerableType show all
Defined in:
lib/icss/type.rb

Overview

Describes an Avro Union type.

Unions are represented using JSON arrays. For example, [“string”, “null”] declares a schema which may be either a string or null.

Unions may not contain more than one schema with the same type, except for the named types record, fixed and enum. For example, unions containing two array types or two map types are not permitted, but two types with different names are permitted. (Names permit efficient resolution when reading and writing unions.)

Unions may not immediately contain other unions.

Constant Summary

Constants inherited from Type

Type::PRIMITIVE_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

find, pig_name, primitive?, #primitive?, #title, #to_json

Instance Attribute Details

#available_typesObject

Returns the value of attribute available_types.



464
465
466
# File 'lib/icss/type.rb', line 464

def available_types
  @available_types
end

#referenced_typesObject

Returns the value of attribute referenced_types.



465
466
467
# File 'lib/icss/type.rb', line 465

def referenced_types
  @referenced_types
end

Instance Method Details

#receive!(type_list) ⇒ Object



468
469
470
471
472
473
474
# File 'lib/icss/type.rb', line 468

def receive! type_list
  self.available_types = type_list.map do |type_info|
    type = TypeFactory.receive(type_info)
    (referenced_types||=[]) << type if (type_info.is_a?(String) || type_info.is_a?(Symbol))
    type
  end
end

#to_hashObject



476
477
478
# File 'lib/icss/type.rb', line 476

def to_hash
  available_types.map{|t| t.name } #  (referenced_types||=[]).include?(t) ? t.name : t.to_hash }
end