Class: Avromatic::Model::TypeRegistry
- Inherits:
-
Object
- Object
- Avromatic::Model::TypeRegistry
- Defined in:
- lib/avromatic/model/type_registry.rb
Instance Method Summary collapse
- #fetch(object) ⇒ Object
-
#initialize ⇒ TypeRegistry
constructor
A new instance of TypeRegistry.
- #register_type(fullname, value_class = nil) ⇒ Object
Constructor Details
#initialize ⇒ TypeRegistry
Returns a new instance of TypeRegistry.
9 10 11 |
# File 'lib/avromatic/model/type_registry.rb', line 9 def initialize @custom_types = {} end |
Instance Method Details
#fetch(object) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/avromatic/model/type_registry.rb', line 26 def fetch(object) field_type = object.is_a?(Avro::Schema::Field) ? object.type : object if field_type.type_sym == :union field_type = Avromatic::Model::Attributes.first_union_schema(field_type) end fullname = field_type.fullname if field_type.is_a?(Avro::Schema::NamedSchema) custom_types.fetch(fullname, NullCustomType) end |
#register_type(fullname, value_class = nil) ⇒ Object
18 19 20 21 22 |
# File 'lib/avromatic/model/type_registry.rb', line 18 def register_type(fullname, value_class = nil) custom_types[fullname.to_s] = Avromatic::Model::CustomType.new(value_class).tap do |type| yield(type) if block_given? end end |