Class: Avromatic::Model::Configuration

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Configuration

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

Parameters:

  • options (Hash)

Options Hash (**options):

  • :schema (Avro::Schema)
  • :schema_name (String, Symbol)
  • :schema_subject (String, Symbol)
  • :value_schema (Avro::Schema)
  • :value_schema_name (String, Symbol)
  • :value_schema_subject (String, Symbol)
  • :key_schema (Avro::Schema)
  • :key_schema_name (String, Symbol)
  • :key_schema_subject (String, Symbol)
  • :nested_models (Avromatic::ModelRegistry)
  • :mutable, (Boolean)

    default false

  • :allow_optional_key_fields, (Boolean)

    default false

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#allow_optional_key_fieldsObject (readonly)

Returns the value of attribute allow_optional_key_fields.



9
10
11
# File 'lib/avromatic/model/configuration.rb', line 9

def allow_optional_key_fields
  @allow_optional_key_fields
end

#avro_schemaObject (readonly) Also known as: value_avro_schema

Returns the value of attribute avro_schema.



9
10
11
# File 'lib/avromatic/model/configuration.rb', line 9

def avro_schema
  @avro_schema
end

#avro_schema_subjectObject (readonly) Also known as: value_avro_schema_subject

Returns the value of attribute avro_schema_subject.



9
10
11
# File 'lib/avromatic/model/configuration.rb', line 9

def avro_schema_subject
  @avro_schema_subject
end

#key_avro_schemaObject (readonly)

Returns the value of attribute key_avro_schema.



9
10
11
# File 'lib/avromatic/model/configuration.rb', line 9

def key_avro_schema
  @key_avro_schema
end

#key_avro_schema_subjectObject (readonly)

Returns the value of attribute key_avro_schema_subject.



9
10
11
# File 'lib/avromatic/model/configuration.rb', line 9

def key_avro_schema_subject
  @key_avro_schema_subject
end

#mutableObject (readonly) Also known as: mutable?

Returns the value of attribute mutable.



9
10
11
# File 'lib/avromatic/model/configuration.rb', line 9

def mutable
  @mutable
end

#nested_modelsObject (readonly)

Returns the value of attribute nested_models.



9
10
11
# File 'lib/avromatic/model/configuration.rb', line 9

def nested_models
  @nested_models
end

Instance Method Details

#immutable?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/avromatic/model/configuration.rb', line 45

def immutable?
  !mutable?
end