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-1.0.0 lib/avromatic/model/nested_models.rb
avromatic-0.33.0 lib/avromatic/model/nested_models.rb
avromatic-0.32.0 lib/avromatic/model/nested_models.rb
avromatic-0.32.0.rc0 lib/avromatic/model/nested_models.rb
avromatic-0.31.0 lib/avromatic/model/nested_models.rb
avromatic-0.30.0 lib/avromatic/model/nested_models.rb
avromatic-0.29.1 lib/avromatic/model/nested_models.rb
avromatic-0.29.0 lib/avromatic/model/nested_models.rb
avromatic-0.28.1 lib/avromatic/model/nested_models.rb
avromatic-0.27.0 lib/avromatic/model/nested_models.rb
avromatic-0.26.0 lib/avromatic/model/nested_models.rb
avromatic-0.25.0 lib/avromatic/model/nested_models.rb
avromatic-0.24.0 lib/avromatic/model/nested_models.rb
avromatic-0.23.0 lib/avromatic/model/nested_models.rb
avromatic-0.22.0 lib/avromatic/model/nested_models.rb
avromatic-0.21.1 lib/avromatic/model/nested_models.rb
avromatic-0.21.0 lib/avromatic/model/nested_models.rb
avromatic-0.21.0.rc1 lib/avromatic/model/nested_models.rb
avromatic-0.21.0.rc0 lib/avromatic/model/nested_models.rb
avromatic-0.20.0 lib/avromatic/model/nested_models.rb