class Avromatic::Model::CustomTypeRegistry
Attributes
Public Class Methods
Source
# File lib/avromatic/model/custom_type_registry.rb, line 11 def initialize @custom_types = {} end
Public Instance Methods
Source
# 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
@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.
Source
# 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
@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.
Source
# 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
@object [Avro::Schema] Custom type may be fetched based on a Avro field
or schema.