avromatic 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +20 -2
- 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/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edd31aa475804bf20a1f5b4ddbe90e8c98460617daeaf2e1641316c08cce505b
|
4
|
+
data.tar.gz: b20ae31b2aeff034f9fa99e2a90d4bb78dfe894967ab8e0267b1df6ee954a15d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e4d441e7645b52840725041d361f699266a9e5dd974e8cd588c8f4750ba21eb4efd016b9c6c20e034a98ed79b673f9aa12a5f0b3a56312a57b344659b93606d
|
7
|
+
data.tar.gz: 5b8ba9cc0049f80a31f88399ca504796997038b969d728be5867d6fd5bc6868786e4ae9dffc0de8a7c1db99e129f9398e4f867794dbd449d54f74c69650735bb
|
data/CHANGELOG.md
CHANGED
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
|
|
@@ -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
|
|
data/lib/avromatic/version.rb
CHANGED
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.0
|
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-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|