Module: Avromatic

Defined in:
lib/avromatic.rb,
lib/avromatic/model.rb,
lib/avromatic/railtie.rb,
lib/avromatic/version.rb,
lib/avromatic/messaging.rb,
lib/avromatic/model/builder.rb,
lib/avromatic/io/union_datum.rb,
lib/avromatic/model_registry.rb,
lib/avromatic/io/datum_reader.rb,
lib/avromatic/io/datum_writer.rb,
lib/avromatic/model/attributes.rb,
lib/avromatic/model/validation.rb,
lib/avromatic/model/configurable.rb,
lib/avromatic/model/field_helper.rb,
lib/avromatic/model/value_object.rb,
lib/avromatic/model/configuration.rb,
lib/avromatic/model/nested_models.rb,
lib/avromatic/model/coercion_error.rb,
lib/avromatic/model/types/map_type.rb,
lib/avromatic/model/message_decoder.rb,
lib/avromatic/model/types/date_type.rb,
lib/avromatic/model/types/enum_type.rb,
lib/avromatic/model/types/null_type.rb,
lib/avromatic/model/types/array_type.rb,
lib/avromatic/model/types/fixed_type.rb,
lib/avromatic/model/types/float_type.rb,
lib/avromatic/model/types/union_type.rb,
lib/avromatic/model/validation_error.rb,
lib/avromatic/model/raw_serialization.rb,
lib/avromatic/model/types/custom_type.rb,
lib/avromatic/model/types/record_type.rb,
lib/avromatic/model/types/string_type.rb,
lib/avromatic/model/types/big_int_type.rb,
lib/avromatic/model/types/boolean_type.rb,
lib/avromatic/model/types/decimal_type.rb,
lib/avromatic/model/types/integer_type.rb,
lib/avromatic/model/types/type_factory.rb,
lib/avromatic/model/types/abstract_type.rb,
lib/avromatic/model/custom_type_registry.rb,
lib/avromatic/model/messaging_serialization.rb,
lib/avromatic/model/unknown_attribute_error.rb,
lib/avromatic/model/custom_type_configuration.rb,
lib/avromatic/model/types/timestamp_micros_type.rb,
lib/avromatic/model/types/timestamp_millis_type.rb,
lib/avromatic/model/types/abstract_timestamp_type.rb

Defined Under Namespace

Modules: IO, Model Classes: Messaging, ModelRegistry, Railtie

Constant Summary collapse

VERSION =
'5.2.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.allow_unknown_attributesObject

Returns the value of attribute allow_unknown_attributes.



14
15
16
# File 'lib/avromatic.rb', line 14

def allow_unknown_attributes
  @allow_unknown_attributes
end

.custom_type_registryObject

Returns the value of attribute custom_type_registry.



14
15
16
# File 'lib/avromatic.rb', line 14

def custom_type_registry
  @custom_type_registry
end

.loggerObject

Returns the value of attribute logger.



14
15
16
# File 'lib/avromatic.rb', line 14

def logger
  @logger
end

.messagingObject

Returns the value of attribute messaging.



14
15
16
# File 'lib/avromatic.rb', line 14

def messaging
  @messaging
end

.nested_modelsObject

Returns the value of attribute nested_models.



14
15
16
# File 'lib/avromatic.rb', line 14

def nested_models
  @nested_models
end

.registry_urlObject

Returns the value of attribute registry_url.



14
15
16
# File 'lib/avromatic.rb', line 14

def registry_url
  @registry_url
end

.schema_registryObject

Returns the value of attribute schema_registry.



14
15
16
# File 'lib/avromatic.rb', line 14

def schema_registry
  @schema_registry
end

.schema_storeObject

Returns the value of attribute schema_store.



14
15
16
# File 'lib/avromatic.rb', line 14

def schema_store
  @schema_store
end

.use_custom_datum_readerObject

Returns the value of attribute use_custom_datum_reader.



14
15
16
# File 'lib/avromatic.rb', line 14

def use_custom_datum_reader
  @use_custom_datum_reader
end

.use_custom_datum_writerObject

Returns the value of attribute use_custom_datum_writer.



14
15
16
# File 'lib/avromatic.rb', line 14

def use_custom_datum_writer
  @use_custom_datum_writer
end

.use_schema_fingerprint_lookupObject

Returns the value of attribute use_schema_fingerprint_lookup.



14
15
16
# File 'lib/avromatic.rb', line 14

def use_schema_fingerprint_lookup
  @use_schema_fingerprint_lookup
end

Class Method Details

.build_messagingObject



52
53
54
55
56
57
58
59
60
# File 'lib/avromatic.rb', line 52

def self.build_messaging
  raise 'Avromatic must be configured with a schema_store' unless schema_store

  Avromatic::Messaging.new(
    registry: schema_registry || build_schema_registry,
    schema_store: schema_store,
    logger: logger
  )
end

.build_messaging!Object



62
63
64
# File 'lib/avromatic.rb', line 62

def self.build_messaging!
  self.messaging = build_messaging
end

.build_schema_registryObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/avromatic.rb', line 34

def self.build_schema_registry
  raise 'Avromatic must be configured with a registry_url' unless registry_url

  if use_schema_fingerprint_lookup
    AvroSchemaRegistry::CachedClient.new(
      AvroSchemaRegistry::Client.new(registry_url, logger: logger)
    )
  else
    AvroTurf::CachedConfluentSchemaRegistry.new(
      AvroTurf::ConfluentSchemaRegistry.new(registry_url, logger: logger)
    )
  end
end

.build_schema_registry!Object



48
49
50
# File 'lib/avromatic.rb', line 48

def self.build_schema_registry!
  self.schema_registry = build_schema_registry
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Avromatic)

    the object that the method was called on



30
31
32
# File 'lib/avromatic.rb', line 30

def self.configure
  yield self
end

.eager_load_modelsObject



85
86
87
# File 'lib/avromatic.rb', line 85

def self.eager_load_models
  @eager_load_model_names
end

.eager_load_models=(models) ⇒ Object



81
82
83
# File 'lib/avromatic.rb', line 81

def self.eager_load_models=(models)
  @eager_load_model_names = Array(models).map { |model| model.is_a?(Class) ? model.name : model }.freeze
end

.prepare!Object

This method is called as a Rails to_prepare hook after the application first initializes during boot-up and prior to each code reloading.



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/avromatic.rb', line 68

def self.prepare!
  nested_models.clear
  if schema_store
    if schema_store.respond_to?(:clear_schemas)
      schema_store.clear_schemas
    elsif schema_store.respond_to?(:clear)
      schema_store.clear
    end
  end

  eager_load_models!
end