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.



460
461
462
# File 'lib/icss/type.rb', line 460

def available_types
  @available_types
end

#referenced_typesObject

Returns the value of attribute referenced_types.



461
462
463
# File 'lib/icss/type.rb', line 461

def referenced_types
  @referenced_types
end

Instance Method Details

#receive!(type_list) ⇒ Object



464
465
466
467
468
469
470
# File 'lib/icss/type.rb', line 464

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



472
473
474
# File 'lib/icss/type.rb', line 472

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