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)
  • :value_schema (Avro::Schema)
  • :value_schema_name (String, Symbol)
  • :key_schema (Avro::Schema)
  • :key_schema_name (String, Symbol)
  • :nested_models (Avromatic::ModelRegistry)
  • :mutable, (Boolean)

    default false

  • :allow_optional_key_fields, (Boolean)

    default false

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
# File 'lib/avromatic/model/configuration.rb', line 27

def initialize(**options)
  @avro_schema = find_avro_schema(**options)
  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)
  @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

#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

#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)


38
39
40
# File 'lib/avromatic/model/configuration.rb', line 38

def immutable?
  !mutable?
end