Class: Avromatic::Model::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/avromatic/model/builder.rb

Overview

This class implements generating models from Avro schemas.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Builder

For options see Avromatic::Model.build



39
40
41
42
43
# File 'lib/avromatic/model/builder.rb', line 39

def initialize(**options)
  @mod = Module.new
  @config = Avromatic::Model::Configuration.new(**options)
  define_included_method
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/avromatic/model/builder.rb', line 22

def config
  @config
end

#modObject (readonly)

Returns the value of attribute mod.



22
23
24
# File 'lib/avromatic/model/builder.rb', line 22

def mod
  @mod
end

Class Method Details

.model(**options, &block) ⇒ Object

For options see Avromatic::Model.build



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/avromatic/model/builder.rb', line 25

def self.model(**options, &block)
  Class.new do
    include Avromatic::Model::Builder.new(**options).mod

    # Name is required for attribute validations on an anonymous class.
    def self.name
      super || (@name ||= config.avro_schema.name.classify)
    end

    class_eval(&block) if block
  end
end

Instance Method Details

#inclusionsObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/avromatic/model/builder.rb', line 45

def inclusions
  [
    Avromatic::Model::Configurable,
    Avromatic::Model::NestedModels,
    Avromatic::Model::Validation,
    Avromatic::Model::Attributes,
    Avromatic::Model::ValueObject,
    Avromatic::Model::RawSerialization,
    Avromatic::Model::MessagingSerialization
  ]
end