deimos-ruby 1.13.2 → 1.14.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +6 -0
  4. data/deimos-ruby.gemspec +1 -0
  5. data/lib/deimos/active_record_consume/message_consumption.rb +2 -1
  6. data/lib/deimos/config/configuration.rb +4 -0
  7. data/lib/deimos/schema_backends/avro_base.rb +1 -1
  8. data/lib/deimos/schema_class/base.rb +17 -0
  9. data/lib/deimos/test_helpers.rb +1 -1
  10. data/lib/deimos/version.rb +1 -1
  11. data/lib/generators/deimos/active_record/templates/migration.rb.tt +5 -3
  12. data/lib/generators/deimos/active_record_generator.rb +1 -1
  13. data/lib/generators/deimos/schema_class/templates/schema_class.rb.tt +0 -7
  14. data/lib/generators/deimos/schema_class/templates/schema_record.rb.tt +10 -1
  15. data/lib/generators/deimos/schema_class_generator.rb +19 -7
  16. data/spec/active_record_consumer_spec.rb +21 -0
  17. data/spec/generators/active_record_generator_spec.rb +4 -2
  18. data/spec/generators/schema_class/my_schema_with_complex_types_spec.rb +37 -24
  19. data/spec/generators/schema_class_generator_spec.rb +93 -55
  20. data/spec/producer_spec.rb +1 -1
  21. data/spec/schemas/com/my-namespace/MySchemaId_key.avsc +12 -0
  22. data/spec/schemas/generated.rb +159 -0
  23. data/spec/schemas/my_nested_schema.rb +117 -0
  24. data/spec/{schema_classes → schemas}/my_schema.rb +1 -0
  25. data/spec/{schema_classes → schemas}/my_schema_key.rb +1 -0
  26. data/spec/schemas/my_schema_with_circular_reference.rb +77 -0
  27. data/spec/schemas/my_schema_with_complex_type.rb +239 -0
  28. data/spec/{schema_classes/generated.rb → snapshots/consumers-no-nest.snap} +20 -1
  29. data/spec/snapshots/consumers.snap +161 -0
  30. data/spec/snapshots/consumers_and_producers-no-nest.snap +397 -0
  31. data/spec/snapshots/consumers_and_producers.snap +377 -0
  32. data/spec/{schema_classes/my_schema_with_circular_reference.rb → snapshots/consumers_circular-no-nest.snap} +37 -26
  33. data/spec/snapshots/consumers_circular.snap +79 -0
  34. data/spec/{schema_classes/my_schema_with_complex_types.rb → snapshots/consumers_complex_types-no-nest.snap} +57 -22
  35. data/spec/snapshots/consumers_complex_types.snap +241 -0
  36. data/spec/{schema_classes/my_nested_schema.rb → snapshots/consumers_nested-no-nest.snap} +12 -1
  37. data/spec/snapshots/consumers_nested.snap +119 -0
  38. data/spec/snapshots/producers_with_key-no-nest.snap +95 -0
  39. data/spec/snapshots/producers_with_key.snap +95 -0
  40. data/spec/spec_helper.rb +4 -1
  41. metadata +54 -14
@@ -0,0 +1,377 @@
1
+ spec/app/lib/schema_classes/generated.rb:
2
+ # frozen_string_literal: true
3
+
4
+ # This file is autogenerated by Deimos, Do NOT modify
5
+ module Schemas
6
+ ### Primary Schema Class ###
7
+ # Autogenerated Schema for Record at com.my-namespace.Generated
8
+ class Generated < Deimos::SchemaClass::Record
9
+
10
+ ### Secondary Schema Classes ###
11
+ # Autogenerated Schema for Record at com.my-namespace.ARecord
12
+ class ARecord < Deimos::SchemaClass::Record
13
+
14
+ ### Attribute Accessors ###
15
+ # @param value [String]
16
+ attr_accessor :a_record_field
17
+
18
+ # @override
19
+ def initialize(a_record_field: nil)
20
+ super
21
+ self.a_record_field = a_record_field
22
+ end
23
+
24
+ # @override
25
+ def schema
26
+ 'ARecord'
27
+ end
28
+
29
+ # @override
30
+ def namespace
31
+ 'com.my-namespace'
32
+ end
33
+
34
+ # @override
35
+ def to_h
36
+ {
37
+ 'a_record_field' => @a_record_field
38
+ }
39
+ end
40
+ end
41
+
42
+ # Autogenerated Schema for Enum at com.my-namespace.AnEnum
43
+ class AnEnum < Deimos::SchemaClass::Enum
44
+ # @return ['sym1', 'sym2']
45
+ attr_accessor :an_enum
46
+
47
+ # :nodoc:
48
+ def initialize(an_enum)
49
+ super
50
+ self.an_enum = an_enum
51
+ end
52
+
53
+ # @override
54
+ def symbols
55
+ %w(sym1 sym2)
56
+ end
57
+
58
+ # @override
59
+ def to_h
60
+ @an_enum
61
+ end
62
+ end
63
+
64
+
65
+ ### Attribute Readers ###
66
+ # @return [AnEnum]
67
+ attr_reader :an_enum
68
+ # @return [ARecord]
69
+ attr_reader :a_record
70
+
71
+ ### Attribute Accessors ###
72
+ # @param value [String]
73
+ attr_accessor :a_string
74
+ # @param value [Integer]
75
+ attr_accessor :a_int
76
+ # @param value [Integer]
77
+ attr_accessor :a_long
78
+ # @param value [Float]
79
+ attr_accessor :a_float
80
+ # @param value [Float]
81
+ attr_accessor :a_double
82
+ # @param value [nil, Integer]
83
+ attr_accessor :an_optional_int
84
+ # @param values [Array<Integer>]
85
+ attr_accessor :an_array
86
+ # @param values [Hash<String, String>]
87
+ attr_accessor :a_map
88
+ # @param value [String]
89
+ attr_accessor :timestamp
90
+ # @param value [String]
91
+ attr_accessor :message_id
92
+
93
+ ### Attribute Writers ###
94
+ # @param value [AnEnum]
95
+ def an_enum=(value)
96
+ @an_enum = AnEnum.initialize_from_value(value)
97
+ end
98
+
99
+ # @param value [ARecord]
100
+ def a_record=(value)
101
+ @a_record = ARecord.initialize_from_value(value)
102
+ end
103
+
104
+ # @override
105
+ def initialize(a_string: nil,
106
+ a_int: nil,
107
+ a_long: nil,
108
+ a_float: nil,
109
+ a_double: nil,
110
+ an_optional_int: nil,
111
+ an_enum: nil,
112
+ an_array: nil,
113
+ a_map: nil,
114
+ timestamp: nil,
115
+ message_id: nil,
116
+ a_record: nil)
117
+ super
118
+ self.a_string = a_string
119
+ self.a_int = a_int
120
+ self.a_long = a_long
121
+ self.a_float = a_float
122
+ self.a_double = a_double
123
+ self.an_optional_int = an_optional_int
124
+ self.an_enum = an_enum
125
+ self.an_array = an_array
126
+ self.a_map = a_map
127
+ self.timestamp = timestamp
128
+ self.message_id = message_id
129
+ self.a_record = a_record
130
+ end
131
+
132
+ # @override
133
+ def schema
134
+ 'Generated'
135
+ end
136
+
137
+ # @override
138
+ def namespace
139
+ 'com.my-namespace'
140
+ end
141
+
142
+ # @override
143
+ def to_h
144
+ {
145
+ 'a_string' => @a_string,
146
+ 'a_int' => @a_int,
147
+ 'a_long' => @a_long,
148
+ 'a_float' => @a_float,
149
+ 'a_double' => @a_double,
150
+ 'an_optional_int' => @an_optional_int,
151
+ 'an_enum' => @an_enum&.to_h,
152
+ 'an_array' => @an_array,
153
+ 'a_map' => @a_map,
154
+ 'timestamp' => @timestamp,
155
+ 'message_id' => @message_id,
156
+ 'a_record' => @a_record&.to_h
157
+ }
158
+ end
159
+ end
160
+ end
161
+
162
+
163
+ spec/app/lib/schema_classes/my_nested_schema.rb:
164
+ # frozen_string_literal: true
165
+
166
+ # This file is autogenerated by Deimos, Do NOT modify
167
+ module Schemas
168
+ ### Primary Schema Class ###
169
+ # Autogenerated Schema for Record at com.my-namespace.MyNestedSchema
170
+ class MyNestedSchema < Deimos::SchemaClass::Record
171
+
172
+ ### Secondary Schema Classes ###
173
+ # Autogenerated Schema for Record at com.my-namespace.MyNestedRecord
174
+ class MyNestedRecord < Deimos::SchemaClass::Record
175
+
176
+ ### Attribute Accessors ###
177
+ # @param value [Integer]
178
+ attr_accessor :some_int
179
+ # @param value [Float]
180
+ attr_accessor :some_float
181
+ # @param value [String]
182
+ attr_accessor :some_string
183
+ # @param value [nil, Integer]
184
+ attr_accessor :some_optional_int
185
+
186
+ # @override
187
+ def initialize(some_int: nil,
188
+ some_float: nil,
189
+ some_string: nil,
190
+ some_optional_int: nil)
191
+ super
192
+ self.some_int = some_int
193
+ self.some_float = some_float
194
+ self.some_string = some_string
195
+ self.some_optional_int = some_optional_int
196
+ end
197
+
198
+ # @override
199
+ def schema
200
+ 'MyNestedRecord'
201
+ end
202
+
203
+ # @override
204
+ def namespace
205
+ 'com.my-namespace'
206
+ end
207
+
208
+ # @override
209
+ def to_h
210
+ {
211
+ 'some_int' => @some_int,
212
+ 'some_float' => @some_float,
213
+ 'some_string' => @some_string,
214
+ 'some_optional_int' => @some_optional_int
215
+ }
216
+ end
217
+ end
218
+
219
+
220
+ ### Attribute Readers ###
221
+ # @return [MyNestedRecord]
222
+ attr_reader :some_nested_record
223
+ # @return [nil, MyNestedRecord]
224
+ attr_reader :some_optional_record
225
+
226
+ ### Attribute Accessors ###
227
+ # @param value [String]
228
+ attr_accessor :test_id
229
+ # @param value [Float]
230
+ attr_accessor :test_float
231
+ # @param values [Array<String>]
232
+ attr_accessor :test_array
233
+
234
+ ### Attribute Writers ###
235
+ # @param value [MyNestedRecord]
236
+ def some_nested_record=(value)
237
+ @some_nested_record = MyNestedRecord.initialize_from_value(value)
238
+ end
239
+
240
+ # @param value [nil, MyNestedRecord]
241
+ def some_optional_record=(value)
242
+ @some_optional_record = MyNestedRecord.initialize_from_value(value)
243
+ end
244
+
245
+ # @override
246
+ def initialize(test_id: nil,
247
+ test_float: nil,
248
+ test_array: nil,
249
+ some_nested_record: nil,
250
+ some_optional_record: nil)
251
+ super
252
+ self.test_id = test_id
253
+ self.test_float = test_float
254
+ self.test_array = test_array
255
+ self.some_nested_record = some_nested_record
256
+ self.some_optional_record = some_optional_record
257
+ end
258
+
259
+ # @override
260
+ def schema
261
+ 'MyNestedSchema'
262
+ end
263
+
264
+ # @override
265
+ def namespace
266
+ 'com.my-namespace'
267
+ end
268
+
269
+ # @override
270
+ def to_h
271
+ {
272
+ 'test_id' => @test_id,
273
+ 'test_float' => @test_float,
274
+ 'test_array' => @test_array,
275
+ 'some_nested_record' => @some_nested_record&.to_h,
276
+ 'some_optional_record' => @some_optional_record&.to_h
277
+ }
278
+ end
279
+ end
280
+ end
281
+
282
+
283
+ spec/app/lib/schema_classes/my_schema.rb:
284
+ # frozen_string_literal: true
285
+
286
+ # This file is autogenerated by Deimos, Do NOT modify
287
+ module Schemas
288
+ ### Primary Schema Class ###
289
+ # Autogenerated Schema for Record at com.my-namespace.MySchema
290
+ class MySchema < Deimos::SchemaClass::Record
291
+
292
+ ### Attribute Readers ###
293
+ # @return [MySchemaKey]
294
+ attr_reader :payload_key
295
+
296
+ ### Attribute Accessors ###
297
+ # @param value [String]
298
+ attr_accessor :test_id
299
+ # @param value [Integer]
300
+ attr_accessor :some_int
301
+
302
+ ### Attribute Writers ###
303
+ # @param value [MySchemaKey]
304
+ def payload_key=(value)
305
+ @payload_key = MySchemaKey.initialize_from_value(value)
306
+ end
307
+
308
+ # @override
309
+ def initialize(test_id: nil,
310
+ some_int: nil,
311
+ payload_key: nil)
312
+ super
313
+ self.test_id = test_id
314
+ self.some_int = some_int
315
+ self.payload_key = payload_key
316
+ end
317
+
318
+ # @override
319
+ def schema
320
+ 'MySchema'
321
+ end
322
+
323
+ # @override
324
+ def namespace
325
+ 'com.my-namespace'
326
+ end
327
+
328
+ # @override
329
+ def to_h
330
+ {
331
+ 'test_id' => @test_id,
332
+ 'some_int' => @some_int,
333
+ 'payload_key' => @payload_key&.to_h
334
+ }
335
+ end
336
+ end
337
+ end
338
+
339
+
340
+ spec/app/lib/schema_classes/my_schema_key.rb:
341
+ # frozen_string_literal: true
342
+
343
+ # This file is autogenerated by Deimos, Do NOT modify
344
+ module Schemas
345
+ ### Primary Schema Class ###
346
+ # Autogenerated Schema for Record at com.my-namespace.MySchema_key
347
+ class MySchemaKey < Deimos::SchemaClass::Record
348
+
349
+ ### Attribute Accessors ###
350
+ # @param value [String]
351
+ attr_accessor :test_id
352
+
353
+ # @override
354
+ def initialize(test_id: nil)
355
+ super
356
+ self.test_id = test_id
357
+ end
358
+
359
+ # @override
360
+ def schema
361
+ 'MySchema_key'
362
+ end
363
+
364
+ # @override
365
+ def namespace
366
+ 'com.my-namespace'
367
+ end
368
+
369
+ # @override
370
+ def to_h
371
+ {
372
+ 'test_id' => @test_id
373
+ }
374
+ end
375
+ end
376
+ end
377
+
@@ -1,23 +1,33 @@
1
+ spec/app/lib/schema_classes/my_schema_with_circular_reference.rb:
1
2
  # frozen_string_literal: true
2
3
 
3
4
  # This file is autogenerated by Deimos, Do NOT modify
4
5
  module Schemas
5
- ### Secondary Schema Classes ###
6
- # Autogenerated Schema for Record at com.my-namespace.Property
7
- class Property < Deimos::SchemaClass::Record
8
- ### Attribute Accessors ###
9
- # @param value [Boolean, Integer, Integer, Float, Float, String, Array<Property>, Hash<String, Property>]
10
- attr_accessor :property
6
+ ### Primary Schema Class ###
7
+ # Autogenerated Schema for Record at com.my-namespace.MySchemaWithCircularReference
8
+ class MySchemaWithCircularReference < Deimos::SchemaClass::Record
9
+
10
+ ### Attribute Readers ###
11
+ # @return [Hash<String, Property>]
12
+ attr_reader :properties
13
+
14
+ ### Attribute Writers ###
15
+ # @param values [Hash<String, Property>]
16
+ def properties=(values)
17
+ @properties = values.transform_values do |value|
18
+ Property.initialize_from_value(value)
19
+ end
20
+ end
11
21
 
12
22
  # @override
13
- def initialize(property: nil)
23
+ def initialize(properties: {})
14
24
  super
15
- self.property = property
25
+ self.properties = properties
16
26
  end
17
27
 
18
28
  # @override
19
29
  def schema
20
- 'Property'
30
+ 'MySchemaWithCircularReference'
21
31
  end
22
32
 
23
33
  # @override
@@ -28,35 +38,35 @@ module Schemas
28
38
  # @override
29
39
  def to_h
30
40
  {
31
- 'property' => @property
41
+ 'properties' => @properties.transform_values { |v| v&.to_h }
32
42
  }
33
43
  end
34
44
  end
45
+ end
46
+
35
47
 
48
+ spec/app/lib/schema_classes/property.rb:
49
+ # frozen_string_literal: true
50
+
51
+ # This file is autogenerated by Deimos, Do NOT modify
52
+ module Schemas
36
53
  ### Primary Schema Class ###
37
- # Autogenerated Schema for Record at com.my-namespace.MySchemaWithCircularReference
38
- class MySchemaWithCircularReference < Deimos::SchemaClass::Record
39
- ### Attribute Readers ###
40
- # @return [Hash<String, Property>]
41
- attr_reader :properties
54
+ # Autogenerated Schema for Record at com.my-namespace.Property
55
+ class Property < Deimos::SchemaClass::Record
42
56
 
43
- ### Attribute Writers ###
44
- # @param values [Hash<String, Property>]
45
- def properties=(values)
46
- @properties = values.transform_values do |value|
47
- Property.initialize_from_value(value)
48
- end
49
- end
57
+ ### Attribute Accessors ###
58
+ # @param value [Boolean, Integer, Integer, Float, Float, String, Array<Property>, Hash<String, Property>]
59
+ attr_accessor :property
50
60
 
51
61
  # @override
52
- def initialize(properties: {})
62
+ def initialize(property: nil)
53
63
  super
54
- self.properties = properties
64
+ self.property = property
55
65
  end
56
66
 
57
67
  # @override
58
68
  def schema
59
- 'MySchemaWithCircularReference'
69
+ 'Property'
60
70
  end
61
71
 
62
72
  # @override
@@ -67,8 +77,9 @@ module Schemas
67
77
  # @override
68
78
  def to_h
69
79
  {
70
- 'properties' => @properties.transform_values { |v| v&.to_h }
80
+ 'property' => @property
71
81
  }
72
82
  end
73
83
  end
74
84
  end
85
+
@@ -0,0 +1,79 @@
1
+ spec/app/lib/schema_classes/my_schema_with_circular_reference.rb:
2
+ # frozen_string_literal: true
3
+
4
+ # This file is autogenerated by Deimos, Do NOT modify
5
+ module Schemas
6
+ ### Primary Schema Class ###
7
+ # Autogenerated Schema for Record at com.my-namespace.MySchemaWithCircularReference
8
+ class MySchemaWithCircularReference < Deimos::SchemaClass::Record
9
+
10
+ ### Secondary Schema Classes ###
11
+ # Autogenerated Schema for Record at com.my-namespace.Property
12
+ class Property < Deimos::SchemaClass::Record
13
+
14
+ ### Attribute Accessors ###
15
+ # @param value [Boolean, Integer, Integer, Float, Float, String, Array<Property>, Hash<String, Property>]
16
+ attr_accessor :property
17
+
18
+ # @override
19
+ def initialize(property: nil)
20
+ super
21
+ self.property = property
22
+ end
23
+
24
+ # @override
25
+ def schema
26
+ 'Property'
27
+ end
28
+
29
+ # @override
30
+ def namespace
31
+ 'com.my-namespace'
32
+ end
33
+
34
+ # @override
35
+ def to_h
36
+ {
37
+ 'property' => @property
38
+ }
39
+ end
40
+ end
41
+
42
+
43
+ ### Attribute Readers ###
44
+ # @return [Hash<String, Property>]
45
+ attr_reader :properties
46
+
47
+ ### Attribute Writers ###
48
+ # @param values [Hash<String, Property>]
49
+ def properties=(values)
50
+ @properties = values.transform_values do |value|
51
+ Property.initialize_from_value(value)
52
+ end
53
+ end
54
+
55
+ # @override
56
+ def initialize(properties: {})
57
+ super
58
+ self.properties = properties
59
+ end
60
+
61
+ # @override
62
+ def schema
63
+ 'MySchemaWithCircularReference'
64
+ end
65
+
66
+ # @override
67
+ def namespace
68
+ 'com.my-namespace'
69
+ end
70
+
71
+ # @override
72
+ def to_h
73
+ {
74
+ 'properties' => @properties.transform_values { |v| v&.to_h }
75
+ }
76
+ end
77
+ end
78
+ end
79
+
@@ -1,10 +1,12 @@
1
+ spec/app/lib/schema_classes/a_record.rb:
1
2
  # frozen_string_literal: true
2
3
 
3
4
  # This file is autogenerated by Deimos, Do NOT modify
4
5
  module Schemas
5
- ### Secondary Schema Classes ###
6
+ ### Primary Schema Class ###
6
7
  # Autogenerated Schema for Record at com.my-namespace.ARecord
7
8
  class ARecord < Deimos::SchemaClass::Record
9
+
8
10
  ### Attribute Accessors ###
9
11
  # @param value [String]
10
12
  attr_accessor :a_record_field
@@ -32,7 +34,15 @@ module Schemas
32
34
  }
33
35
  end
34
36
  end
37
+ end
35
38
 
39
+
40
+ spec/app/lib/schema_classes/an_enum.rb:
41
+ # frozen_string_literal: true
42
+
43
+ # This file is autogenerated by Deimos, Do NOT modify
44
+ module Schemas
45
+ ### Primary Schema Class ###
36
46
  # Autogenerated Schema for Enum at com.my-namespace.AnEnum
37
47
  class AnEnum < Deimos::SchemaClass::Enum
38
48
  # @return ['sym1', 'sym2']
@@ -54,7 +64,15 @@ module Schemas
54
64
  @an_enum
55
65
  end
56
66
  end
67
+ end
68
+
57
69
 
70
+ spec/app/lib/schema_classes/another_enum.rb:
71
+ # frozen_string_literal: true
72
+
73
+ # This file is autogenerated by Deimos, Do NOT modify
74
+ module Schemas
75
+ ### Primary Schema Class ###
58
76
  # Autogenerated Schema for Enum at com.my-namespace.AnotherEnum
59
77
  class AnotherEnum < Deimos::SchemaClass::Enum
60
78
  # @return ['sym3', 'sym4']
@@ -76,32 +94,18 @@ module Schemas
76
94
  @another_enum
77
95
  end
78
96
  end
97
+ end
79
98
 
80
- # Autogenerated Schema for Enum at com.my-namespace.YetAnotherEnum
81
- class YetAnotherEnum < Deimos::SchemaClass::Enum
82
- # @return ['sym5', 'sym6']
83
- attr_accessor :yet_another_enum
84
-
85
- # :nodoc:
86
- def initialize(yet_another_enum)
87
- super
88
- self.yet_another_enum = yet_another_enum
89
- end
90
-
91
- # @override
92
- def symbols
93
- %w(sym5 sym6)
94
- end
95
99
 
96
- # @override
97
- def to_h
98
- @yet_another_enum
99
- end
100
- end
100
+ spec/app/lib/schema_classes/my_schema_with_complex_type.rb:
101
+ # frozen_string_literal: true
101
102
 
103
+ # This file is autogenerated by Deimos, Do NOT modify
104
+ module Schemas
102
105
  ### Primary Schema Class ###
103
106
  # Autogenerated Schema for Record at com.my-namespace.MySchemaWithComplexTypes
104
- class MySchemaWithComplexTypes < Deimos::SchemaClass::Record
107
+ class MySchemaWithComplexType < Deimos::SchemaClass::Record
108
+
105
109
  ### Attribute Readers ###
106
110
  # @return [ARecord]
107
111
  attr_reader :some_record
@@ -234,3 +238,34 @@ module Schemas
234
238
  end
235
239
  end
236
240
  end
241
+
242
+
243
+ spec/app/lib/schema_classes/yet_another_enum.rb:
244
+ # frozen_string_literal: true
245
+
246
+ # This file is autogenerated by Deimos, Do NOT modify
247
+ module Schemas
248
+ ### Primary Schema Class ###
249
+ # Autogenerated Schema for Enum at com.my-namespace.YetAnotherEnum
250
+ class YetAnotherEnum < Deimos::SchemaClass::Enum
251
+ # @return ['sym5', 'sym6']
252
+ attr_accessor :yet_another_enum
253
+
254
+ # :nodoc:
255
+ def initialize(yet_another_enum)
256
+ super
257
+ self.yet_another_enum = yet_another_enum
258
+ end
259
+
260
+ # @override
261
+ def symbols
262
+ %w(sym5 sym6)
263
+ end
264
+
265
+ # @override
266
+ def to_h
267
+ @yet_another_enum
268
+ end
269
+ end
270
+ end
271
+