class Avromatic::Model::Configuration

This class holds configuration for a model built from Avro schema(s).

Attributes

allow_optional_key_fields[R]
avro_schema[R]
avro_schema_subject[R]
key_avro_schema[R]
key_avro_schema_subject[R]
mutable[R]
mutable?[R]
nested_models[R]
value_avro_schema[R]
value_avro_schema_subject[R]

Public Class Methods

new(**options) click to toggle source

Either schema(_name) or value_schema(_name), but not both, must be specified.

@param options [Hash] @option options [Avro::Schema] :schema @option options [String, Symbol] :schema_name @option options [String, Symbol] :schema_subject @option options [Avro::Schema] :value_schema @option options [String, Symbol] :value_schema_name @option options [String, Symbol] :value_schema_subject @option options [Avro::Schema] :key_schema @option options [String, Symbol] :key_schema_name @option options [String, Symbol] :key_schema_subject @option options [Avromatic::ModelRegistry] :nested_models @option options [Boolean] :mutable, default false @option options [Boolean] :allow_optional_key_fields, default false

# File lib/avromatic/model/configuration.rb, line 30
def initialize(**options)
  @avro_schema = find_avro_schema(**options)
  @avro_schema_subject = options[:schema_subject] || options[:value_schema_subject]
  raise ArgumentError.new('value_schema(_name) or schema(_name) must be specified') unless avro_schema

  @key_avro_schema = find_schema_by_option(:key_schema, **options)
  @key_avro_schema_subject = options[:key_schema_subject]
  @nested_models = options[:nested_models]
  @mutable = options.fetch(:mutable, false)
  @allow_optional_key_fields = options.fetch(:allow_optional_key_fields, false)
end

Public Instance Methods

immutable?() click to toggle source
# File lib/avromatic/model/configuration.rb, line 45
def immutable?
  !mutable?
end

Private Instance Methods

find_avro_schema(**options) click to toggle source
# File lib/avromatic/model/configuration.rb, line 51
def find_avro_schema(**options)
  if (options[:value_schema] || options[:value_schema_name]) &&
    (options[:schema] || options[:schema_name])
    raise ArgumentError.new('Only one of value_schema(_name) and schema(_name) can be specified')
  end

  find_schema_by_option(:value_schema, **options) || find_schema_by_option(:schema, **options)
end
find_schema_by_option(option_name, **options) click to toggle source
# File lib/avromatic/model/configuration.rb, line 60
def find_schema_by_option(option_name, **options)
  schema_name_option = :"#{option_name}_name"
  options[option_name] ||
    (options[schema_name_option] && schema_store.find(options[schema_name_option]))
end