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/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/boolean_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/patches/schema_validator_patch.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

Overview

rubocop:disable Style/WhenThen

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'2.2.4'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.allow_unknown_attributesObject

Returns the value of attribute allow_unknown_attributes.



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

def allow_unknown_attributes
  @allow_unknown_attributes
end

.custom_type_registryObject

Returns the value of attribute custom_type_registry.



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

def custom_type_registry
  @custom_type_registry
end

.loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

.messagingObject

Returns the value of attribute messaging.



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

def messaging
  @messaging
end

.nested_modelsObject

Returns the value of attribute nested_models.



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

def nested_models
  @nested_models
end

.registry_urlObject

Returns the value of attribute registry_url.



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

def registry_url
  @registry_url
end

.schema_registryObject

Returns the value of attribute schema_registry.



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

def schema_registry
  @schema_registry
end

.schema_storeObject

Returns the value of attribute schema_store.



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

def schema_store
  @schema_store
end

.use_custom_datum_readerObject

Returns the value of attribute use_custom_datum_reader.



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

def use_custom_datum_reader
  @use_custom_datum_reader
end

.use_custom_datum_writerObject

Returns the value of attribute use_custom_datum_writer.



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

def use_custom_datum_writer
  @use_custom_datum_writer
end

.use_schema_fingerprint_lookupObject

Returns the value of attribute use_schema_fingerprint_lookup.



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

def use_schema_fingerprint_lookup
  @use_schema_fingerprint_lookup
end

Class Method Details

.build_messagingObject



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

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



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/avromatic.rb', line 40

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



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

def self.configure
  yield self
  eager_load_models!
end

.eager_load_models=(models) ⇒ Object



83
84
85
# File 'lib/avromatic.rb', line 83

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.



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

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)


36
37
38
# File 'lib/avromatic.rb', line 36

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