class Avromatic::Model::CustomTypeRegistry

Attributes

custom_types[R]

Public Class Methods

new() click to toggle source
# File lib/avromatic/model/custom_type_registry.rb, line 11
def initialize
  @custom_types = {}
end

Public Instance Methods

fetch(object) click to toggle source

@object [Avro::Schema] Custom type may be fetched based on a Avro field

or schema. If there is no custom type, then an exception will be thrown.

@field_class [Object] Value class that has been determined for a field.

# File lib/avromatic/model/custom_type_registry.rb, line 36
def fetch(object)
  field_type = object.is_a?(Avro::Schema::Field) ? object.type : object
  fullname = field_type.fullname if field_type.is_a?(Avro::Schema::NamedSchema)
  custom_types.fetch(fullname)
end
register_type(fullname, value_class = nil) { |type| ... } click to toggle source

@param fullname [String] The fullname of the Avro type. @param value_class [Class] Optional class to use for the attribute.

If unspecified then the default class for the Avro field is used.

@block If a block is specified then the CustomType is yielded for

additional configuration.
# File lib/avromatic/model/custom_type_registry.rb, line 20
def register_type(fullname, value_class = nil)
  custom_types[fullname.to_s] = Avromatic::Model::CustomTypeConfiguration.new(value_class).tap do |type|
    yield(type) if block_given?
  end
end
registered?(object) click to toggle source

@object [Avro::Schema] Custom type may be fetched based on a Avro field

or schema.
# File lib/avromatic/model/custom_type_registry.rb, line 28
def registered?(object)
  field_type = object.is_a?(Avro::Schema::Field) ? object.type : object
  custom_types.include?(field_type.fullname) if field_type.is_a?(Avro::Schema::NamedSchema)
end