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,239 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is autogenerated by Deimos, Do NOT modify
4
+ module Schemas
5
+ ### Primary Schema Class ###
6
+ # Autogenerated Schema for Record at com.my-namespace.MySchemaWithComplexTypes
7
+ class MySchemaWithComplexType < Deimos::SchemaClass::Record
8
+
9
+ ### Secondary Schema Classes ###
10
+ # Autogenerated Schema for Record at com.my-namespace.ARecord
11
+ class ARecord < Deimos::SchemaClass::Record
12
+
13
+ ### Attribute Accessors ###
14
+ # @param value [String]
15
+ attr_accessor :a_record_field
16
+
17
+ # @override
18
+ def initialize(a_record_field: nil)
19
+ super
20
+ self.a_record_field = a_record_field
21
+ end
22
+
23
+ # @override
24
+ def schema
25
+ 'ARecord'
26
+ end
27
+
28
+ # @override
29
+ def namespace
30
+ 'com.my-namespace'
31
+ end
32
+
33
+ # @override
34
+ def to_h
35
+ {
36
+ 'a_record_field' => @a_record_field
37
+ }
38
+ end
39
+ end
40
+
41
+ # Autogenerated Schema for Enum at com.my-namespace.AnEnum
42
+ class AnEnum < Deimos::SchemaClass::Enum
43
+ # @return ['sym1', 'sym2']
44
+ attr_accessor :an_enum
45
+
46
+ # :nodoc:
47
+ def initialize(an_enum)
48
+ super
49
+ self.an_enum = an_enum
50
+ end
51
+
52
+ # @override
53
+ def symbols
54
+ %w(sym1 sym2)
55
+ end
56
+
57
+ # @override
58
+ def to_h
59
+ @an_enum
60
+ end
61
+ end
62
+
63
+ # Autogenerated Schema for Enum at com.my-namespace.AnotherEnum
64
+ class AnotherEnum < Deimos::SchemaClass::Enum
65
+ # @return ['sym3', 'sym4']
66
+ attr_accessor :another_enum
67
+
68
+ # :nodoc:
69
+ def initialize(another_enum)
70
+ super
71
+ self.another_enum = another_enum
72
+ end
73
+
74
+ # @override
75
+ def symbols
76
+ %w(sym3 sym4)
77
+ end
78
+
79
+ # @override
80
+ def to_h
81
+ @another_enum
82
+ end
83
+ end
84
+
85
+ # Autogenerated Schema for Enum at com.my-namespace.YetAnotherEnum
86
+ class YetAnotherEnum < Deimos::SchemaClass::Enum
87
+ # @return ['sym5', 'sym6']
88
+ attr_accessor :yet_another_enum
89
+
90
+ # :nodoc:
91
+ def initialize(yet_another_enum)
92
+ super
93
+ self.yet_another_enum = yet_another_enum
94
+ end
95
+
96
+ # @override
97
+ def symbols
98
+ %w(sym5 sym6)
99
+ end
100
+
101
+ # @override
102
+ def to_h
103
+ @yet_another_enum
104
+ end
105
+ end
106
+
107
+
108
+ ### Attribute Readers ###
109
+ # @return [ARecord]
110
+ attr_reader :some_record
111
+ # @return [nil, ARecord]
112
+ attr_reader :some_optional_record
113
+ # @return [Array<ARecord>]
114
+ attr_reader :some_record_array
115
+ # @return [Hash<String, ARecord>]
116
+ attr_reader :some_record_map
117
+ # @return [Array<AnEnum>]
118
+ attr_reader :some_enum_array
119
+ # @return [nil, AnotherEnum]
120
+ attr_reader :some_optional_enum
121
+ # @return [YetAnotherEnum]
122
+ attr_reader :some_enum_with_default
123
+
124
+ ### Attribute Accessors ###
125
+ # @param value [String]
126
+ attr_accessor :test_id
127
+ # @param value [Float]
128
+ attr_accessor :test_float
129
+ # @param values [Array<String>]
130
+ attr_accessor :test_string_array
131
+ # @param values [Array<Integer>]
132
+ attr_accessor :test_int_array
133
+ # @param value [Integer, nil]
134
+ attr_accessor :test_optional_int
135
+ # @param values [Hash<String, Integer>]
136
+ attr_accessor :some_integer_map
137
+
138
+ ### Attribute Writers ###
139
+ # @param value [ARecord]
140
+ def some_record=(value)
141
+ @some_record = ARecord.initialize_from_value(value)
142
+ end
143
+
144
+ # @param value [nil, ARecord]
145
+ def some_optional_record=(value)
146
+ @some_optional_record = ARecord.initialize_from_value(value)
147
+ end
148
+
149
+ # @param values [Array<ARecord>]
150
+ def some_record_array=(values)
151
+ @some_record_array = values.map do |value|
152
+ ARecord.initialize_from_value(value)
153
+ end
154
+ end
155
+
156
+ # @param values [Hash<String, ARecord>]
157
+ def some_record_map=(values)
158
+ @some_record_map = values.transform_values do |value|
159
+ ARecord.initialize_from_value(value)
160
+ end
161
+ end
162
+
163
+ # @param values [Array<AnEnum>]
164
+ def some_enum_array=(values)
165
+ @some_enum_array = values.map do |value|
166
+ AnEnum.initialize_from_value(value)
167
+ end
168
+ end
169
+
170
+ # @param value [nil, AnotherEnum]
171
+ def some_optional_enum=(value)
172
+ @some_optional_enum = AnotherEnum.initialize_from_value(value)
173
+ end
174
+
175
+ # @param value [YetAnotherEnum]
176
+ def some_enum_with_default=(value)
177
+ @some_enum_with_default = YetAnotherEnum.initialize_from_value(value)
178
+ end
179
+
180
+ # @override
181
+ def initialize(test_id: nil,
182
+ test_float: nil,
183
+ test_string_array: ["test"],
184
+ test_int_array: [123],
185
+ test_optional_int: 123,
186
+ some_integer_map: {"abc"=>123},
187
+ some_record: {"a_record_field"=>"Test String"},
188
+ some_optional_record: nil,
189
+ some_record_array: nil,
190
+ some_record_map: nil,
191
+ some_enum_array: nil,
192
+ some_optional_enum: nil,
193
+ some_enum_with_default: "sym6")
194
+ super
195
+ self.test_id = test_id
196
+ self.test_float = test_float
197
+ self.test_string_array = test_string_array
198
+ self.test_int_array = test_int_array
199
+ self.test_optional_int = test_optional_int
200
+ self.some_integer_map = some_integer_map
201
+ self.some_record = some_record
202
+ self.some_optional_record = some_optional_record
203
+ self.some_record_array = some_record_array
204
+ self.some_record_map = some_record_map
205
+ self.some_enum_array = some_enum_array
206
+ self.some_optional_enum = some_optional_enum
207
+ self.some_enum_with_default = some_enum_with_default
208
+ end
209
+
210
+ # @override
211
+ def schema
212
+ 'MySchemaWithComplexTypes'
213
+ end
214
+
215
+ # @override
216
+ def namespace
217
+ 'com.my-namespace'
218
+ end
219
+
220
+ # @override
221
+ def to_h
222
+ {
223
+ 'test_id' => @test_id,
224
+ 'test_float' => @test_float,
225
+ 'test_string_array' => @test_string_array,
226
+ 'test_int_array' => @test_int_array,
227
+ 'test_optional_int' => @test_optional_int,
228
+ 'some_integer_map' => @some_integer_map,
229
+ 'some_record' => @some_record&.to_h,
230
+ 'some_optional_record' => @some_optional_record&.to_h,
231
+ 'some_record_array' => @some_record_array.map { |v| v&.to_h },
232
+ 'some_record_map' => @some_record_map.transform_values { |v| v&.to_h },
233
+ 'some_enum_array' => @some_enum_array.map { |v| v&.to_h },
234
+ 'some_optional_enum' => @some_optional_enum&.to_h,
235
+ 'some_enum_with_default' => @some_enum_with_default&.to_h
236
+ }
237
+ end
238
+ end
239
+ end
@@ -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,10 +64,18 @@ module Schemas
54
64
  @an_enum
55
65
  end
56
66
  end
67
+ end
68
+
69
+
70
+ spec/app/lib/schema_classes/generated.rb:
71
+ # frozen_string_literal: true
57
72
 
73
+ # This file is autogenerated by Deimos, Do NOT modify
74
+ module Schemas
58
75
  ### Primary Schema Class ###
59
76
  # Autogenerated Schema for Record at com.my-namespace.Generated
60
77
  class Generated < Deimos::SchemaClass::Record
78
+
61
79
  ### Attribute Readers ###
62
80
  # @return [AnEnum]
63
81
  attr_reader :an_enum
@@ -154,3 +172,4 @@ module Schemas
154
172
  end
155
173
  end
156
174
  end
175
+
@@ -0,0 +1,161 @@
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
+