Module: Avromatic::Model::Attributes

Extended by:
ActiveSupport::Concern
Defined in:
lib/avromatic/model/attributes.rb

Overview

This module supports defining Virtus attributes for a model based on the fields of Avro schemas.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.first_union_schema(field_type) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/avromatic/model/attributes.rb', line 12

def self.first_union_schema(field_type)
  # TODO: This is a hack until I find a better solution for unions with
  # Virtus. This only handles a union for an optional field with :null
  # and one other type.
  schemas = field_type.schemas.reject { |schema| schema.type_sym == :null }
  raise "Only the union of null with one other type is supported #{field_type}" if schemas.size > 1
  schemas.first
end