Class: Avromatic::Model::CustomTypeRegistry
- Inherits:
-
Object
- Object
- Avromatic::Model::CustomTypeRegistry
- Defined in:
- lib/avromatic/model/custom_type_registry.rb
Instance Method Summary collapse
- #fetch(object) ⇒ Object
-
#initialize ⇒ CustomTypeRegistry
constructor
A new instance of CustomTypeRegistry.
- #register_type(fullname, value_class = nil) ⇒ Object
- #registered?(object) ⇒ Boolean
Constructor Details
#initialize ⇒ CustomTypeRegistry
Returns a new instance of CustomTypeRegistry.
11 12 13 |
# File 'lib/avromatic/model/custom_type_registry.rb', line 11 def initialize @custom_types = {} end |
Instance Method Details
#fetch(object) ⇒ Object
36 37 38 39 40 |
# 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) ⇒ Object
20 21 22 23 24 |
# 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) ⇒ Boolean
28 29 30 31 |
# 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 |