Module: Avromatic::Model::NestedModels::ClassMethods

Defined in:
lib/avromatic/model/nested_models.rb

Instance Method Summary collapse

Instance Method Details

#referenced_model_classesObject



29
30
31
# File 'lib/avromatic/model/nested_models.rb', line 29

def referenced_model_classes
  attribute_definitions.values.flat_map { |definition| definition.type.referenced_model_classes }.freeze
end

#register!Object

Register this model if it can be used as a nested model.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/avromatic/model/nested_models.rb', line 14

def register!
  return unless key_avro_schema.nil? && value_avro_schema.type_sym == :record

  processed = Set.new
  roots = [self]
  until roots.empty?
    model = roots.shift
    # Avoid any nested model dependency cycles by ignoring already processed models
    next unless processed.add?(model)

    nested_models.ensure_registered_model(model)
    roots.concat(model.referenced_model_classes)
  end
end