Sha256: 58dc265156c22171734d763d2a8c49b90ce7b3e18b792e0cd1c9c35f1b6079ed

Contents?: true

Size: 1.14 KB

Versions: 46

Compression:

Stored size: 1.14 KB

Contents

require 'active_support/inflector/methods'

module Avromatic
  module Model
    # This module handles integration with the ModelRegistry and support
    # for nested model reuse.
    module NestedModels
      extend ActiveSupport::Concern

      module ClassMethods
        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 this model if it can be used as a nested model.
        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
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
avromatic-0.19.0 lib/avromatic/model/nested_models.rb
avromatic-0.18.1 lib/avromatic/model/nested_models.rb
avromatic-0.18.0 lib/avromatic/model/nested_models.rb
avromatic-0.18.0.rc0 lib/avromatic/model/nested_models.rb
avromatic-0.17.1 lib/avromatic/model/nested_models.rb
avromatic-0.17.0 lib/avromatic/model/nested_models.rb
avromatic-0.15.1 lib/avromatic/model/nested_models.rb
avromatic-0.15.0 lib/avromatic/model/nested_models.rb
avromatic-0.15.0.rc0 lib/avromatic/model/nested_models.rb
avromatic-0.14.0 lib/avromatic/model/nested_models.rb
avromatic-0.14.0.rc1 lib/avromatic/model/nested_models.rb
avromatic-0.14.0.rc0 lib/avromatic/model/nested_models.rb
avromatic-0.13.0 lib/avromatic/model/nested_models.rb
avromatic-0.13.0.rc1 lib/avromatic/model/nested_models.rb
avromatic-0.13.0.rc0 lib/avromatic/model/nested_models.rb
avromatic-0.12.0 lib/avromatic/model/nested_models.rb
avromatic-0.11.2 lib/avromatic/model/nested_models.rb
avromatic-0.11.1 lib/avromatic/model/nested_models.rb
avromatic-0.11.0 lib/avromatic/model/nested_models.rb
avromatic-0.10.0 lib/avromatic/model/nested_models.rb