Module: Avromatic

Defined in:
lib/avromatic/io/datum_reader.rb,
lib/avromatic.rb,
lib/avromatic/io.rb,
lib/avromatic/model.rb,
lib/avromatic/railtie.rb,
lib/avromatic/version.rb,
lib/avromatic/messaging.rb,
lib/avromatic/model/builder.rb,
lib/avromatic/model_registry.rb,
lib/avromatic/io/datum_writer.rb,
lib/avromatic/model/attributes.rb,
lib/avromatic/model/validation.rb,
lib/avromatic/model/custom_type.rb,
lib/avromatic/model/configurable.rb,
lib/avromatic/model/value_object.rb,
lib/avromatic/model/configuration.rb,
lib/avromatic/model/logical_types.rb,
lib/avromatic/model/nested_models.rb,
lib/avromatic/model/type_registry.rb,
lib/avromatic/model/attribute/union.rb,
lib/avromatic/model/message_decoder.rb,
lib/avromatic/model/attribute/record.rb,
lib/avromatic/model/null_custom_type.rb,
lib/avromatic/model/raw_serialization.rb,
lib/avromatic/model/attribute_type/union.rb,
lib/avromatic/model/passthrough_serializer.rb,
lib/avromatic/model/messaging_serialization.rb,
lib/avromatic/patches/schema_validator_patch.rb,
lib/avromatic/model/attribute/timestamp_micros.rb,
lib/avromatic/model/attribute/timestamp_millis.rb,
lib/avromatic/model/attribute/abstract_timestamp.rb,
lib/avromatic/model/allowed_writer_methods_memoization.rb

Overview

rubocop:disable Style/WhenThen

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'1.0.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/avromatic.rb', line 11

def logger
  @logger
end

.messagingObject

Returns the value of attribute messaging.



11
12
13
# File 'lib/avromatic.rb', line 11

def messaging
  @messaging
end

.nested_modelsObject

Returns the value of attribute nested_models.



11
12
13
# File 'lib/avromatic.rb', line 11

def nested_models
  @nested_models
end

.registry_urlObject

Returns the value of attribute registry_url.



11
12
13
# File 'lib/avromatic.rb', line 11

def registry_url
  @registry_url
end

.schema_registryObject

Returns the value of attribute schema_registry.



11
12
13
# File 'lib/avromatic.rb', line 11

def schema_registry
  @schema_registry
end

.schema_storeObject

Returns the value of attribute schema_store.



11
12
13
# File 'lib/avromatic.rb', line 11

def schema_store
  @schema_store
end

.type_registryObject

Returns the value of attribute type_registry.



11
12
13
# File 'lib/avromatic.rb', line 11

def type_registry
  @type_registry
end

.use_custom_datum_readerObject

Returns the value of attribute use_custom_datum_reader.



11
12
13
# File 'lib/avromatic.rb', line 11

def use_custom_datum_reader
  @use_custom_datum_reader
end

.use_custom_datum_writerObject

Returns the value of attribute use_custom_datum_writer.



11
12
13
# File 'lib/avromatic.rb', line 11

def use_custom_datum_writer
  @use_custom_datum_writer
end

.use_schema_fingerprint_lookupObject

Returns the value of attribute use_schema_fingerprint_lookup.



11
12
13
# File 'lib/avromatic.rb', line 11

def use_schema_fingerprint_lookup
  @use_schema_fingerprint_lookup
end

Class Method Details

.build_messagingObject



48
49
50
51
52
53
54
55
# File 'lib/avromatic.rb', line 48

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



57
58
59
# File 'lib/avromatic.rb', line 57

def self.build_messaging!
  self.messaging = build_messaging
end

.build_schema_registryObject



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

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

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

Yields:

  • (_self)

Yield Parameters:

  • _self (Avromatic)

    the object that the method was called on



26
27
28
29
# File 'lib/avromatic.rb', line 26

def self.configure
  yield self
  eager_load_models!
end

.eager_load_models=(models) ⇒ Object



78
79
80
# File 'lib/avromatic.rb', line 78

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

.prepare!(skip_clear: false) ⇒ 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. For the first call during boot-up we do not want to clear the nested_models.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/avromatic.rb', line 64

def self.prepare!(skip_clear: false)
  unless skip_clear
    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
  end
  eager_load_models!
end

.use_encoding_providers?Boolean

Returns:

  • (Boolean)


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

def self.use_encoding_providers?
  use_custom_datum_writer && defined?(Avromatic::Patches::SchemaValidatorPatch)
end