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

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

Instance Method Summary collapse

Instance Method Details

#build_nested_model(schema) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/avromatic/model/nested_models.rb', line 11

def build_nested_model(schema)
  fullname = nested_models.remove_prefix(schema.fullname)

  if nested_models.registered?(fullname)
    nested_models[fullname]
  else
    Avromatic::Model.model(schema: schema,
                           nested_models: nested_models)
  end
end

#register!Object

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



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/avromatic/model/nested_models.rb', line 23

def register!
  if key_avro_schema.nil? && value_avro_schema.type_sym == :record
    # Register the generated model with Axiom to prevent it being
    # treated as a BasicObject.
    # See https://github.com/solnic/virtus/issues/284#issuecomment-56405137
    nested_model = self
    Axiom::Types::Object.new { primitive(nested_model) }

    nested_models.register(self)
  end
end