avromatic 4.0.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +21 -3
- data/avromatic.gemspec +1 -1
- data/lib/avromatic/model/configurable.rb +3 -1
- data/lib/avromatic/model/configuration.rb +7 -1
- data/lib/avromatic/model/messaging_serialization.rb +8 -6
- data/lib/avromatic/model/types/type_factory.rb +2 -2
- data/lib/avromatic/railtie.rb +1 -12
- data/lib/avromatic/version.rb +1 -1
- data/lib/avromatic.rb +8 -11
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bec6621c5d35e04596185542eaa4d96d00ef67f86f24b26378c68b22ecb3b3c
|
4
|
+
data.tar.gz: 1468ebd3138c5dc63a5d18d86dab5757df5c67109867628d1161b01ef70db1f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da43c835a7f56011c1ed194bba7a02e5f98a190f65a8ce025b67f8a23d9a43093e2e64f83cdaf520d847c37ecf66cfd6ed276aee7f195a9f3f2b0c248967f5bf
|
7
|
+
data.tar.gz: 920048102d5947af69eca3d4e4c357adf9eefaebbd83e8d70190d29a6fb8d30c65072c97fda65613d9ebed32e127f98d9f4952e1e91e081963e61a480a002af3
|
data/.github/CODEOWNERS
CHANGED
@@ -1 +1 @@
|
|
1
|
-
* @jturkel @
|
1
|
+
* @jturkel @tjwp @salsify/infrastructure-services
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# avromatic changelog
|
2
2
|
|
3
|
+
## 4.1.1
|
4
|
+
- Fix eager loading of nested models when using the Zeitwerk classloader with Rails.
|
5
|
+
|
6
|
+
## 4.1.0
|
7
|
+
- Add support for specifying a subject for the avro schema when building an Avromatic model
|
8
|
+
|
3
9
|
## 4.0.0
|
4
10
|
- Drop support for Ruby 2.6.
|
5
11
|
- Drop support for Avro 1.9.
|
data/README.md
CHANGED
@@ -124,7 +124,7 @@ The Avro schema can be specified by name and loaded using the schema store:
|
|
124
124
|
|
125
125
|
```ruby
|
126
126
|
class MyModel
|
127
|
-
include Avromatic::Model.build(schema_name :my_model)
|
127
|
+
include Avromatic::Model.build(schema_name: :my_model)
|
128
128
|
end
|
129
129
|
|
130
130
|
# Construct instances by passing in a hash of attributes
|
@@ -156,12 +156,20 @@ class MyModel
|
|
156
156
|
end
|
157
157
|
```
|
158
158
|
|
159
|
+
A specific subject name can be associated with the schema:
|
160
|
+
```ruby
|
161
|
+
class MyModel
|
162
|
+
include Avromatic::Model.build(schema_name: 'my_model',
|
163
|
+
schema_subject: 'my_model-value')
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
159
167
|
Models are generated as immutable value
|
160
168
|
objects by default, but can optionally be defined as mutable:
|
161
169
|
|
162
170
|
```ruby
|
163
171
|
class MyModel
|
164
|
-
include Avromatic::Model.build(schema_name :my_model, mutable: true)
|
172
|
+
include Avromatic::Model.build(schema_name: :my_model, mutable: true)
|
165
173
|
end
|
166
174
|
```
|
167
175
|
|
@@ -195,6 +203,16 @@ class MyTopic
|
|
195
203
|
end
|
196
204
|
```
|
197
205
|
|
206
|
+
A specific subject name can be associated with both the value and key schemas:
|
207
|
+
```ruby
|
208
|
+
class MyTopic
|
209
|
+
include Avromatic::Model.build(value_schema_name: :topic_value,
|
210
|
+
value_schema_subject: 'topic_value-value',
|
211
|
+
key_schema_name: :topic_key,
|
212
|
+
key_schema_subject: 'topic_key-value')
|
213
|
+
end
|
214
|
+
```
|
215
|
+
|
198
216
|
A model can also be generated as an anonymous class that can be assigned to a
|
199
217
|
constant:
|
200
218
|
|
@@ -268,7 +286,7 @@ correct order:
|
|
268
286
|
Avromatic.configure do |config|
|
269
287
|
config.eager_load_models = [
|
270
288
|
# reference any extended models that should be defined first
|
271
|
-
MyNestedModel
|
289
|
+
'MyNestedModel'
|
272
290
|
]
|
273
291
|
end
|
274
292
|
```
|
data/avromatic.gemspec
CHANGED
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
|
|
45
45
|
spec.add_development_dependency 'rake', '~> 13.0'
|
46
46
|
spec.add_development_dependency 'rspec', '~> 3.8'
|
47
47
|
spec.add_development_dependency 'rspec_junit_formatter'
|
48
|
-
spec.add_development_dependency 'salsify_rubocop', '~> 1.1
|
48
|
+
spec.add_development_dependency 'salsify_rubocop', '~> 1.27.1'
|
49
49
|
spec.add_development_dependency 'simplecov'
|
50
50
|
spec.add_development_dependency 'webmock'
|
51
51
|
# For AvroSchemaRegistry::FakeServer
|
@@ -24,7 +24,8 @@ module Avromatic
|
|
24
24
|
end
|
25
25
|
|
26
26
|
module ClassMethods
|
27
|
-
delegate :avro_schema, :value_avro_schema, :key_avro_schema, :mutable?, :immutable?,
|
27
|
+
delegate :avro_schema, :value_avro_schema, :key_avro_schema, :mutable?, :immutable?,
|
28
|
+
:avro_schema_subject, :value_avro_schema_subject, :key_avro_schema_subject, to: :config
|
28
29
|
|
29
30
|
def value_avro_field_names
|
30
31
|
@value_avro_field_names ||= value_avro_schema.fields.map(&:name).map(&:to_sym).freeze
|
@@ -68,6 +69,7 @@ module Avromatic
|
|
68
69
|
end
|
69
70
|
|
70
71
|
delegate :avro_schema, :value_avro_schema, :key_avro_schema,
|
72
|
+
:avro_schema_subject, :value_avro_schema_subject, :key_avro_schema_subject,
|
71
73
|
:value_avro_field_names, :key_avro_field_names,
|
72
74
|
:value_avro_field_references, :key_avro_field_references,
|
73
75
|
:mutable?, :immutable?,
|
@@ -7,7 +7,7 @@ module Avromatic
|
|
7
7
|
class Configuration
|
8
8
|
|
9
9
|
attr_reader :avro_schema, :key_avro_schema, :nested_models, :mutable,
|
10
|
-
:allow_optional_key_fields
|
10
|
+
:allow_optional_key_fields, :avro_schema_subject, :key_avro_schema_subject
|
11
11
|
alias_method :mutable?, :mutable
|
12
12
|
delegate :schema_store, to: Avromatic
|
13
13
|
|
@@ -17,24 +17,30 @@ module Avromatic
|
|
17
17
|
# @param options [Hash]
|
18
18
|
# @option options [Avro::Schema] :schema
|
19
19
|
# @option options [String, Symbol] :schema_name
|
20
|
+
# @option options [String, Symbol] :schema_subject
|
20
21
|
# @option options [Avro::Schema] :value_schema
|
21
22
|
# @option options [String, Symbol] :value_schema_name
|
23
|
+
# @option options [String, Symbol] :value_schema_subject
|
22
24
|
# @option options [Avro::Schema] :key_schema
|
23
25
|
# @option options [String, Symbol] :key_schema_name
|
26
|
+
# @option options [String, Symbol] :key_schema_subject
|
24
27
|
# @option options [Avromatic::ModelRegistry] :nested_models
|
25
28
|
# @option options [Boolean] :mutable, default false
|
26
29
|
# @option options [Boolean] :allow_optional_key_fields, default false
|
27
30
|
def initialize(**options)
|
28
31
|
@avro_schema = find_avro_schema(**options)
|
32
|
+
@avro_schema_subject = options[:schema_subject] || options[:value_schema_subject]
|
29
33
|
raise ArgumentError.new('value_schema(_name) or schema(_name) must be specified') unless avro_schema
|
30
34
|
|
31
35
|
@key_avro_schema = find_schema_by_option(:key_schema, **options)
|
36
|
+
@key_avro_schema_subject = options[:key_schema_subject]
|
32
37
|
@nested_models = options[:nested_models]
|
33
38
|
@mutable = options.fetch(:mutable, false)
|
34
39
|
@allow_optional_key_fields = options.fetch(:allow_optional_key_fields, false)
|
35
40
|
end
|
36
41
|
|
37
42
|
alias_method :value_avro_schema, :avro_schema
|
43
|
+
alias_method :value_avro_schema_subject, :avro_schema_subject
|
38
44
|
|
39
45
|
def immutable?
|
40
46
|
!mutable?
|
@@ -16,7 +16,8 @@ module Avromatic
|
|
16
16
|
def avro_message_value
|
17
17
|
avro_messaging.encode(
|
18
18
|
value_attributes_for_avro,
|
19
|
-
schema_name: value_avro_schema.fullname
|
19
|
+
schema_name: value_avro_schema.fullname,
|
20
|
+
subject: value_avro_schema_subject
|
20
21
|
)
|
21
22
|
end
|
22
23
|
|
@@ -25,7 +26,8 @@ module Avromatic
|
|
25
26
|
|
26
27
|
avro_messaging.encode(
|
27
28
|
key_attributes_for_avro,
|
28
|
-
schema_name: key_avro_schema.fullname
|
29
|
+
schema_name: key_avro_schema.fullname,
|
30
|
+
subject: key_avro_schema_subject
|
29
31
|
)
|
30
32
|
end
|
31
33
|
end
|
@@ -56,15 +58,15 @@ module Avromatic
|
|
56
58
|
|
57
59
|
module Registration
|
58
60
|
def register_schemas!
|
59
|
-
register_schema(key_avro_schema) if key_avro_schema
|
60
|
-
register_schema(value_avro_schema)
|
61
|
+
register_schema(key_avro_schema, subject: key_avro_schema_subject) if key_avro_schema
|
62
|
+
register_schema(value_avro_schema, subject: value_avro_schema_subject)
|
61
63
|
nil
|
62
64
|
end
|
63
65
|
|
64
66
|
private
|
65
67
|
|
66
|
-
def register_schema(schema)
|
67
|
-
avro_messaging.registry.register(schema.fullname, schema)
|
68
|
+
def register_schema(schema, subject: nil)
|
69
|
+
avro_messaging.registry.register(subject || schema.fullname, schema)
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
@@ -60,11 +60,11 @@ module Avromatic
|
|
60
60
|
Avromatic::Model::Types::EnumType.new(schema.symbols)
|
61
61
|
when :array
|
62
62
|
value_type = create(schema: schema.items, nested_models: nested_models,
|
63
|
-
use_custom_types: use_custom_types)
|
63
|
+
use_custom_types: use_custom_types)
|
64
64
|
Avromatic::Model::Types::ArrayType.new(value_type: value_type)
|
65
65
|
when :map
|
66
66
|
value_type = create(schema: schema.values, nested_models: nested_models,
|
67
|
-
use_custom_types: use_custom_types)
|
67
|
+
use_custom_types: use_custom_types)
|
68
68
|
Avromatic::Model::Types::MapType.new(
|
69
69
|
key_type: Avromatic::Model::Types::StringType.new,
|
70
70
|
value_type: value_type
|
data/lib/avromatic/railtie.rb
CHANGED
@@ -7,19 +7,8 @@ module Avromatic
|
|
7
7
|
config.logger = Rails.logger
|
8
8
|
end
|
9
9
|
|
10
|
-
# Rails calls the to_prepare hook once during boot-up, after running
|
11
|
-
# initializers. After the to_prepare call during boot-up, no code will
|
12
|
-
# we reloaded, so we need to retain the contents of the nested_models
|
13
|
-
# registry.
|
14
|
-
#
|
15
|
-
# For subsequent calls to to_prepare (in development), the nested_models
|
16
|
-
# registry is cleared and repopulated by explicitly referencing the
|
17
|
-
# eager_loaded_models.
|
18
|
-
first_prepare = true
|
19
|
-
|
20
10
|
Rails.configuration.to_prepare do
|
21
|
-
Avromatic.prepare!
|
22
|
-
first_prepare = false
|
11
|
+
Avromatic.prepare!
|
23
12
|
end
|
24
13
|
end
|
25
14
|
end
|
data/lib/avromatic/version.rb
CHANGED
data/lib/avromatic.rb
CHANGED
@@ -29,7 +29,6 @@ module Avromatic
|
|
29
29
|
|
30
30
|
def self.configure
|
31
31
|
yield self
|
32
|
-
eager_load_models!
|
33
32
|
end
|
34
33
|
|
35
34
|
def self.build_schema_registry
|
@@ -66,18 +65,16 @@ module Avromatic
|
|
66
65
|
|
67
66
|
# This method is called as a Rails to_prepare hook after the application
|
68
67
|
# first initializes during boot-up and prior to each code reloading.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
elsif schema_store.respond_to?(:clear)
|
77
|
-
schema_store.clear
|
78
|
-
end
|
68
|
+
def self.prepare!
|
69
|
+
nested_models.clear
|
70
|
+
if schema_store
|
71
|
+
if schema_store.respond_to?(:clear_schemas)
|
72
|
+
schema_store.clear_schemas
|
73
|
+
elsif schema_store.respond_to?(:clear)
|
74
|
+
schema_store.clear
|
79
75
|
end
|
80
76
|
end
|
77
|
+
|
81
78
|
eager_load_models!
|
82
79
|
end
|
83
80
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avromatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -216,14 +216,14 @@ dependencies:
|
|
216
216
|
requirements:
|
217
217
|
- - "~>"
|
218
218
|
- !ruby/object:Gem::Version
|
219
|
-
version: 1.1
|
219
|
+
version: 1.27.1
|
220
220
|
type: :development
|
221
221
|
prerelease: false
|
222
222
|
version_requirements: !ruby/object:Gem::Requirement
|
223
223
|
requirements:
|
224
224
|
- - "~>"
|
225
225
|
- !ruby/object:Gem::Version
|
226
|
-
version: 1.1
|
226
|
+
version: 1.27.1
|
227
227
|
- !ruby/object:Gem::Dependency
|
228
228
|
name: simplecov
|
229
229
|
requirement: !ruby/object:Gem::Requirement
|
@@ -364,7 +364,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
364
364
|
- !ruby/object:Gem::Version
|
365
365
|
version: '0'
|
366
366
|
requirements: []
|
367
|
-
rubygems_version: 3.
|
367
|
+
rubygems_version: 3.3.7
|
368
368
|
signing_key:
|
369
369
|
specification_version: 4
|
370
370
|
summary: Generate Ruby models from Avro schemas
|