deimos-ruby 1.13.3 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +6 -0
  4. data/deimos-ruby.gemspec +1 -0
  5. data/lib/deimos/config/configuration.rb +4 -0
  6. data/lib/deimos/schema_backends/avro_base.rb +1 -1
  7. data/lib/deimos/version.rb +1 -1
  8. data/lib/generators/deimos/schema_class/templates/schema_class.rb.tt +0 -7
  9. data/lib/generators/deimos/schema_class/templates/schema_record.rb.tt +10 -1
  10. data/lib/generators/deimos/schema_class_generator.rb +19 -7
  11. data/spec/generators/active_record_generator_spec.rb +4 -2
  12. data/spec/generators/schema_class/my_schema_with_complex_types_spec.rb +37 -24
  13. data/spec/generators/schema_class_generator_spec.rb +93 -55
  14. data/spec/producer_spec.rb +1 -1
  15. data/spec/schemas/generated.rb +159 -0
  16. data/spec/schemas/my_nested_schema.rb +117 -0
  17. data/spec/{schema_classes → schemas}/my_schema.rb +1 -0
  18. data/spec/{schema_classes → schemas}/my_schema_key.rb +1 -0
  19. data/spec/schemas/my_schema_with_circular_reference.rb +77 -0
  20. data/spec/schemas/my_schema_with_complex_type.rb +239 -0
  21. data/spec/{schema_classes/generated.rb → snapshots/consumers-no-nest.snap} +20 -1
  22. data/spec/snapshots/consumers.snap +161 -0
  23. data/spec/snapshots/consumers_and_producers-no-nest.snap +397 -0
  24. data/spec/snapshots/consumers_and_producers.snap +377 -0
  25. data/spec/{schema_classes/my_schema_with_circular_reference.rb → snapshots/consumers_circular-no-nest.snap} +37 -26
  26. data/spec/snapshots/consumers_circular.snap +79 -0
  27. data/spec/{schema_classes/my_schema_with_complex_types.rb → snapshots/consumers_complex_types-no-nest.snap} +57 -22
  28. data/spec/snapshots/consumers_complex_types.snap +241 -0
  29. data/spec/{schema_classes/my_nested_schema.rb → snapshots/consumers_nested-no-nest.snap} +12 -1
  30. data/spec/snapshots/consumers_nested.snap +119 -0
  31. data/spec/snapshots/producers_with_key-no-nest.snap +95 -0
  32. data/spec/snapshots/producers_with_key.snap +95 -0
  33. data/spec/spec_helper.rb +4 -1
  34. metadata +52 -14
@@ -0,0 +1,159 @@
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.Generated
7
+ class Generated < 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
+
64
+ ### Attribute Readers ###
65
+ # @return [AnEnum]
66
+ attr_reader :an_enum
67
+ # @return [ARecord]
68
+ attr_reader :a_record
69
+
70
+ ### Attribute Accessors ###
71
+ # @param value [String]
72
+ attr_accessor :a_string
73
+ # @param value [Integer]
74
+ attr_accessor :a_int
75
+ # @param value [Integer]
76
+ attr_accessor :a_long
77
+ # @param value [Float]
78
+ attr_accessor :a_float
79
+ # @param value [Float]
80
+ attr_accessor :a_double
81
+ # @param value [nil, Integer]
82
+ attr_accessor :an_optional_int
83
+ # @param values [Array<Integer>]
84
+ attr_accessor :an_array
85
+ # @param values [Hash<String, String>]
86
+ attr_accessor :a_map
87
+ # @param value [String]
88
+ attr_accessor :timestamp
89
+ # @param value [String]
90
+ attr_accessor :message_id
91
+
92
+ ### Attribute Writers ###
93
+ # @param value [AnEnum]
94
+ def an_enum=(value)
95
+ @an_enum = AnEnum.initialize_from_value(value)
96
+ end
97
+
98
+ # @param value [ARecord]
99
+ def a_record=(value)
100
+ @a_record = ARecord.initialize_from_value(value)
101
+ end
102
+
103
+ # @override
104
+ def initialize(a_string: nil,
105
+ a_int: nil,
106
+ a_long: nil,
107
+ a_float: nil,
108
+ a_double: nil,
109
+ an_optional_int: nil,
110
+ an_enum: nil,
111
+ an_array: nil,
112
+ a_map: nil,
113
+ timestamp: nil,
114
+ message_id: nil,
115
+ a_record: nil)
116
+ super
117
+ self.a_string = a_string
118
+ self.a_int = a_int
119
+ self.a_long = a_long
120
+ self.a_float = a_float
121
+ self.a_double = a_double
122
+ self.an_optional_int = an_optional_int
123
+ self.an_enum = an_enum
124
+ self.an_array = an_array
125
+ self.a_map = a_map
126
+ self.timestamp = timestamp
127
+ self.message_id = message_id
128
+ self.a_record = a_record
129
+ end
130
+
131
+ # @override
132
+ def schema
133
+ 'Generated'
134
+ end
135
+
136
+ # @override
137
+ def namespace
138
+ 'com.my-namespace'
139
+ end
140
+
141
+ # @override
142
+ def to_h
143
+ {
144
+ 'a_string' => @a_string,
145
+ 'a_int' => @a_int,
146
+ 'a_long' => @a_long,
147
+ 'a_float' => @a_float,
148
+ 'a_double' => @a_double,
149
+ 'an_optional_int' => @an_optional_int,
150
+ 'an_enum' => @an_enum&.to_h,
151
+ 'an_array' => @an_array,
152
+ 'a_map' => @a_map,
153
+ 'timestamp' => @timestamp,
154
+ 'message_id' => @message_id,
155
+ 'a_record' => @a_record&.to_h
156
+ }
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,117 @@
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.MyNestedSchema
7
+ class MyNestedSchema < Deimos::SchemaClass::Record
8
+
9
+ ### Secondary Schema Classes ###
10
+ # Autogenerated Schema for Record at com.my-namespace.MyNestedRecord
11
+ class MyNestedRecord < Deimos::SchemaClass::Record
12
+
13
+ ### Attribute Accessors ###
14
+ # @param value [Integer]
15
+ attr_accessor :some_int
16
+ # @param value [Float]
17
+ attr_accessor :some_float
18
+ # @param value [String]
19
+ attr_accessor :some_string
20
+ # @param value [nil, Integer]
21
+ attr_accessor :some_optional_int
22
+
23
+ # @override
24
+ def initialize(some_int: nil,
25
+ some_float: nil,
26
+ some_string: nil,
27
+ some_optional_int: nil)
28
+ super
29
+ self.some_int = some_int
30
+ self.some_float = some_float
31
+ self.some_string = some_string
32
+ self.some_optional_int = some_optional_int
33
+ end
34
+
35
+ # @override
36
+ def schema
37
+ 'MyNestedRecord'
38
+ end
39
+
40
+ # @override
41
+ def namespace
42
+ 'com.my-namespace'
43
+ end
44
+
45
+ # @override
46
+ def to_h
47
+ {
48
+ 'some_int' => @some_int,
49
+ 'some_float' => @some_float,
50
+ 'some_string' => @some_string,
51
+ 'some_optional_int' => @some_optional_int
52
+ }
53
+ end
54
+ end
55
+
56
+
57
+ ### Attribute Readers ###
58
+ # @return [MyNestedRecord]
59
+ attr_reader :some_nested_record
60
+ # @return [nil, MyNestedRecord]
61
+ attr_reader :some_optional_record
62
+
63
+ ### Attribute Accessors ###
64
+ # @param value [String]
65
+ attr_accessor :test_id
66
+ # @param value [Float]
67
+ attr_accessor :test_float
68
+ # @param values [Array<String>]
69
+ attr_accessor :test_array
70
+
71
+ ### Attribute Writers ###
72
+ # @param value [MyNestedRecord]
73
+ def some_nested_record=(value)
74
+ @some_nested_record = MyNestedRecord.initialize_from_value(value)
75
+ end
76
+
77
+ # @param value [nil, MyNestedRecord]
78
+ def some_optional_record=(value)
79
+ @some_optional_record = MyNestedRecord.initialize_from_value(value)
80
+ end
81
+
82
+ # @override
83
+ def initialize(test_id: nil,
84
+ test_float: nil,
85
+ test_array: nil,
86
+ some_nested_record: nil,
87
+ some_optional_record: nil)
88
+ super
89
+ self.test_id = test_id
90
+ self.test_float = test_float
91
+ self.test_array = test_array
92
+ self.some_nested_record = some_nested_record
93
+ self.some_optional_record = some_optional_record
94
+ end
95
+
96
+ # @override
97
+ def schema
98
+ 'MyNestedSchema'
99
+ end
100
+
101
+ # @override
102
+ def namespace
103
+ 'com.my-namespace'
104
+ end
105
+
106
+ # @override
107
+ def to_h
108
+ {
109
+ 'test_id' => @test_id,
110
+ 'test_float' => @test_float,
111
+ 'test_array' => @test_array,
112
+ 'some_nested_record' => @some_nested_record&.to_h,
113
+ 'some_optional_record' => @some_optional_record&.to_h
114
+ }
115
+ end
116
+ end
117
+ end
@@ -5,6 +5,7 @@ module Schemas
5
5
  ### Primary Schema Class ###
6
6
  # Autogenerated Schema for Record at com.my-namespace.MySchema
7
7
  class MySchema < Deimos::SchemaClass::Record
8
+
8
9
  ### Attribute Readers ###
9
10
  # @return [MySchemaKey]
10
11
  attr_reader :payload_key
@@ -5,6 +5,7 @@ module Schemas
5
5
  ### Primary Schema Class ###
6
6
  # Autogenerated Schema for Record at com.my-namespace.MySchema_key
7
7
  class MySchemaKey < Deimos::SchemaClass::Record
8
+
8
9
  ### Attribute Accessors ###
9
10
  # @param value [String]
10
11
  attr_accessor :test_id
@@ -0,0 +1,77 @@
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.MySchemaWithCircularReference
7
+ class MySchemaWithCircularReference < Deimos::SchemaClass::Record
8
+
9
+ ### Secondary Schema Classes ###
10
+ # Autogenerated Schema for Record at com.my-namespace.Property
11
+ class Property < Deimos::SchemaClass::Record
12
+
13
+ ### Attribute Accessors ###
14
+ # @param value [Boolean, Integer, Integer, Float, Float, String, Array<Property>, Hash<String, Property>]
15
+ attr_accessor :property
16
+
17
+ # @override
18
+ def initialize(property: nil)
19
+ super
20
+ self.property = property
21
+ end
22
+
23
+ # @override
24
+ def schema
25
+ 'Property'
26
+ end
27
+
28
+ # @override
29
+ def namespace
30
+ 'com.my-namespace'
31
+ end
32
+
33
+ # @override
34
+ def to_h
35
+ {
36
+ 'property' => @property
37
+ }
38
+ end
39
+ end
40
+
41
+
42
+ ### Attribute Readers ###
43
+ # @return [Hash<String, Property>]
44
+ attr_reader :properties
45
+
46
+ ### Attribute Writers ###
47
+ # @param values [Hash<String, Property>]
48
+ def properties=(values)
49
+ @properties = values.transform_values do |value|
50
+ Property.initialize_from_value(value)
51
+ end
52
+ end
53
+
54
+ # @override
55
+ def initialize(properties: {})
56
+ super
57
+ self.properties = properties
58
+ end
59
+
60
+ # @override
61
+ def schema
62
+ 'MySchemaWithCircularReference'
63
+ end
64
+
65
+ # @override
66
+ def namespace
67
+ 'com.my-namespace'
68
+ end
69
+
70
+ # @override
71
+ def to_h
72
+ {
73
+ 'properties' => @properties.transform_values { |v| v&.to_h }
74
+ }
75
+ end
76
+ end
77
+ end
@@ -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
+