deimos-ruby 2.5.3 → 2.6.0.pre.beta1
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/CHANGELOG.md +2 -0
- data/README.md +20 -9
- data/deimos-ruby.gemspec +1 -0
- data/docs/CONFIGURATION.md +11 -4
- data/lib/deimos/active_record_consume/batch_consumption.rb +1 -1
- data/lib/deimos/active_record_consume/message_consumption.rb +2 -2
- data/lib/deimos/active_record_consumer.rb +1 -1
- data/lib/deimos/active_record_producer.rb +1 -1
- data/lib/deimos/config/configuration.rb +34 -11
- data/lib/deimos/ext/producer_middleware.rb +2 -2
- data/lib/deimos/logging.rb +9 -0
- data/lib/deimos/producer.rb +5 -5
- data/lib/deimos/schema_backends/avro_base.rb +7 -36
- data/lib/deimos/schema_class.rb +72 -0
- data/lib/deimos/transcoder.rb +6 -6
- data/lib/deimos/utils/schema_class.rb +14 -47
- data/lib/deimos/version.rb +1 -1
- data/lib/deimos.rb +3 -3
- data/lib/tasks/deimos.rake +16 -4
- data/regenerate_test_schema_classes.rb +12 -3
- data/spec/active_record_batch_consumer_association_spec.rb +1 -1
- data/spec/active_record_batch_consumer_spec.rb +1 -1
- data/spec/active_record_consume/batch_consumption_spec.rb +1 -1
- data/spec/active_record_consumer_spec.rb +3 -3
- data/spec/active_record_producer_spec.rb +1 -1
- data/spec/batch_consumer_spec.rb +2 -2
- data/spec/consumer_spec.rb +9 -9
- data/spec/schema_class_spec.rb +65 -0
- data/spec/schemas/my_namespace/generated.rb +4 -4
- data/spec/schemas/my_namespace/my_long_namespace_schema.rb +2 -2
- data/spec/schemas/my_namespace/my_nested_schema.rb +3 -3
- data/spec/schemas/my_namespace/my_schema.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_compound_key.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_id_key.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_key.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_boolean.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_circular_reference.rb +3 -3
- data/spec/schemas/my_namespace/my_schema_with_complex_type.rb +6 -6
- data/spec/schemas/my_namespace/my_schema_with_date_time.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_id.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_title.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_union_type.rb +6 -6
- data/spec/schemas/my_namespace/my_schema_with_unique_id.rb +2 -2
- data/spec/schemas/my_namespace/my_updated_schema.rb +1 -1
- data/spec/schemas/my_namespace/request/create_topic.rb +2 -2
- data/spec/schemas/my_namespace/request/index.rb +2 -2
- data/spec/schemas/my_namespace/request/update_request.rb +2 -2
- data/spec/schemas/my_namespace/response/create_topic.rb +2 -2
- data/spec/schemas/my_namespace/response/index.rb +2 -2
- data/spec/schemas/my_namespace/response/update_response.rb +2 -2
- data/spec/schemas/my_namespace/wibble.rb +2 -2
- data/spec/schemas/my_namespace/widget.rb +2 -2
- data/spec/schemas/my_namespace/widget_the_second.rb +2 -2
- data/spec/schemas/my_namespace/widget_the_third.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/utils/db_poller_spec.rb +1 -1
- metadata +18 -27
- data/lib/deimos/schema_class/base.rb +0 -62
- data/lib/deimos/schema_class/enum.rb +0 -49
- data/lib/deimos/schema_class/record.rb +0 -100
- data/lib/generators/deimos/schema_class/templates/schema_class.rb.tt +0 -8
- data/lib/generators/deimos/schema_class/templates/schema_enum.rb.tt +0 -13
- data/lib/generators/deimos/schema_class/templates/schema_record.rb.tt +0 -102
- data/lib/generators/deimos/schema_class_generator.rb +0 -369
- data/spec/generators/schema_class/my_schema_spec.rb +0 -16
- data/spec/generators/schema_class/my_schema_with_circular_reference_spec.rb +0 -98
- data/spec/generators/schema_class/my_schema_with_complex_types_spec.rb +0 -237
- data/spec/generators/schema_class_generator_spec.rb +0 -283
- data/spec/snapshots/consumers-no-nest.snap +0 -1740
- data/spec/snapshots/consumers.snap +0 -1720
- data/spec/snapshots/consumers_and_producers-no-nest.snap +0 -1740
- data/spec/snapshots/consumers_and_producers.snap +0 -1720
- data/spec/snapshots/consumers_circular-no-nest.snap +0 -1740
- data/spec/snapshots/consumers_circular.snap +0 -1720
- data/spec/snapshots/consumers_complex_types-no-nest.snap +0 -1740
- data/spec/snapshots/consumers_complex_types.snap +0 -1720
- data/spec/snapshots/consumers_nested-no-nest.snap +0 -1740
- data/spec/snapshots/consumers_nested.snap +0 -1720
- data/spec/snapshots/namespace_folders.snap +0 -1800
- data/spec/snapshots/namespace_map.snap +0 -1800
- data/spec/snapshots/producers_with_key-no-nest.snap +0 -1740
- data/spec/snapshots/producers_with_key.snap +0 -1720
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# This file is autogenerated by
|
|
3
|
+
# This file is autogenerated by AvroGen, Do NOT modify
|
|
4
4
|
module Schemas; module MyNamespace
|
|
5
5
|
### Primary Schema Class ###
|
|
6
6
|
# Autogenerated Schema for Record at com.my-namespace.Widget
|
|
7
|
-
class Widget <
|
|
7
|
+
class Widget < AvroGen::SchemaClass::Record
|
|
8
8
|
|
|
9
9
|
### Attribute Accessors ###
|
|
10
10
|
# @return [Integer]
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# This file is autogenerated by
|
|
3
|
+
# This file is autogenerated by AvroGen, Do NOT modify
|
|
4
4
|
module Schemas; module MyNamespace
|
|
5
5
|
### Primary Schema Class ###
|
|
6
6
|
# Autogenerated Schema for Record at com.my-namespace.WidgetTheSecond
|
|
7
|
-
class WidgetTheSecond <
|
|
7
|
+
class WidgetTheSecond < AvroGen::SchemaClass::Record
|
|
8
8
|
|
|
9
9
|
### Attribute Accessors ###
|
|
10
10
|
# @return [Integer]
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# This file is autogenerated by
|
|
3
|
+
# This file is autogenerated by AvroGen, Do NOT modify
|
|
4
4
|
module Schemas; module MyNamespace
|
|
5
5
|
### Primary Schema Class ###
|
|
6
6
|
# Autogenerated Schema for Record at com.my-namespace.WidgetTheThird
|
|
7
|
-
class WidgetTheThird <
|
|
7
|
+
class WidgetTheThird < AvroGen::SchemaClass::Record
|
|
8
8
|
|
|
9
9
|
### Attribute Accessors ###
|
|
10
10
|
# @return [String]
|
data/spec/spec_helper.rb
CHANGED
|
@@ -223,13 +223,13 @@ RSpec.configure do |config|
|
|
|
223
223
|
set_karafka_config(:reraise_errors, true)
|
|
224
224
|
Deimos.configure do |deimos_config|
|
|
225
225
|
deimos_config.producers.backend = :kafka
|
|
226
|
-
deimos_config.
|
|
226
|
+
deimos_config.avrogen.nest_child_schemas = true
|
|
227
227
|
deimos_config.schema.path = File.join(File.expand_path(__dir__), 'schemas')
|
|
228
228
|
deimos_config.schema.registry_url = ENV['SCHEMA_REGISTRY'] || 'http://localhost:8081'
|
|
229
229
|
deimos_config.logger = Logger.new(File::NULL)
|
|
230
230
|
deimos_config.logger.level = Logger::INFO
|
|
231
231
|
deimos_config.schema.backend = :avro_validation
|
|
232
|
-
deimos_config.
|
|
232
|
+
deimos_config.avrogen.generated_class_path = 'spec/schemas'
|
|
233
233
|
end
|
|
234
234
|
end
|
|
235
235
|
|
|
@@ -316,7 +316,7 @@ each_db_config(Deimos::Utils::DbPoller::Base) do
|
|
|
316
316
|
m.call(*args)
|
|
317
317
|
expect(info.reload.last_sent.in_time_zone).to eq(time_value(mins: -61, secs: 32))
|
|
318
318
|
expect(info.last_sent_id).to eq(widgets[1].id)
|
|
319
|
-
|
|
319
|
+
end
|
|
320
320
|
expect(poller).to receive(:process_and_touch_info).ordered.
|
|
321
321
|
with([widgets[2], widgets[3], widgets[4]], anything).and_call_original
|
|
322
322
|
expect(poller).to receive(:process_and_touch_info).ordered.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deimos-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.6.0.pre.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Orner
|
|
@@ -9,6 +9,20 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: avro-gen-ruby
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: benchmark
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -536,9 +550,7 @@ files:
|
|
|
536
550
|
- lib/deimos/schema_backends/proto_base.rb
|
|
537
551
|
- lib/deimos/schema_backends/proto_local.rb
|
|
538
552
|
- lib/deimos/schema_backends/proto_schema_registry.rb
|
|
539
|
-
- lib/deimos/schema_class
|
|
540
|
-
- lib/deimos/schema_class/enum.rb
|
|
541
|
-
- lib/deimos/schema_class/record.rb
|
|
553
|
+
- lib/deimos/schema_class.rb
|
|
542
554
|
- lib/deimos/shared_config.rb
|
|
543
555
|
- lib/deimos/test_helpers.rb
|
|
544
556
|
- lib/deimos/tracing/datadog.rb
|
|
@@ -564,10 +576,6 @@ files:
|
|
|
564
576
|
- lib/generators/deimos/outbox_backend/templates/migration
|
|
565
577
|
- lib/generators/deimos/outbox_backend/templates/rails3_migration
|
|
566
578
|
- lib/generators/deimos/outbox_backend_generator.rb
|
|
567
|
-
- lib/generators/deimos/schema_class/templates/schema_class.rb.tt
|
|
568
|
-
- lib/generators/deimos/schema_class/templates/schema_enum.rb.tt
|
|
569
|
-
- lib/generators/deimos/schema_class/templates/schema_record.rb.tt
|
|
570
|
-
- lib/generators/deimos/schema_class_generator.rb
|
|
571
579
|
- lib/generators/deimos/v2/templates/karafka.rb.tt
|
|
572
580
|
- lib/generators/deimos/v2_generator.rb
|
|
573
581
|
- lib/tasks/deimos.rake
|
|
@@ -595,10 +603,6 @@ files:
|
|
|
595
603
|
- spec/gen/sample/v1/sample_key_pb.rb
|
|
596
604
|
- spec/gen/sample/v1/sample_pb.rb
|
|
597
605
|
- spec/generators/active_record_generator_spec.rb
|
|
598
|
-
- spec/generators/schema_class/my_schema_spec.rb
|
|
599
|
-
- spec/generators/schema_class/my_schema_with_circular_reference_spec.rb
|
|
600
|
-
- spec/generators/schema_class/my_schema_with_complex_types_spec.rb
|
|
601
|
-
- spec/generators/schema_class_generator_spec.rb
|
|
602
606
|
- spec/handlers/my_batch_consumer.rb
|
|
603
607
|
- spec/handlers/my_consumer.rb
|
|
604
608
|
- spec/kafka_source_spec.rb
|
|
@@ -618,6 +622,7 @@ files:
|
|
|
618
622
|
- spec/schema_backends/avro_validation_spec.rb
|
|
619
623
|
- spec/schema_backends/base_spec.rb
|
|
620
624
|
- spec/schema_backends/proto_schema_registry_spec.rb
|
|
625
|
+
- spec/schema_class_spec.rb
|
|
621
626
|
- spec/schemas/com/my-namespace/Generated.avsc
|
|
622
627
|
- spec/schemas/com/my-namespace/MyNestedSchema.avsc
|
|
623
628
|
- spec/schemas/com/my-namespace/MySchema.avsc
|
|
@@ -669,20 +674,6 @@ files:
|
|
|
669
674
|
- spec/schemas/my_namespace/widget.rb
|
|
670
675
|
- spec/schemas/my_namespace/widget_the_second.rb
|
|
671
676
|
- spec/schemas/my_namespace/widget_the_third.rb
|
|
672
|
-
- spec/snapshots/consumers-no-nest.snap
|
|
673
|
-
- spec/snapshots/consumers.snap
|
|
674
|
-
- spec/snapshots/consumers_and_producers-no-nest.snap
|
|
675
|
-
- spec/snapshots/consumers_and_producers.snap
|
|
676
|
-
- spec/snapshots/consumers_circular-no-nest.snap
|
|
677
|
-
- spec/snapshots/consumers_circular.snap
|
|
678
|
-
- spec/snapshots/consumers_complex_types-no-nest.snap
|
|
679
|
-
- spec/snapshots/consumers_complex_types.snap
|
|
680
|
-
- spec/snapshots/consumers_nested-no-nest.snap
|
|
681
|
-
- spec/snapshots/consumers_nested.snap
|
|
682
|
-
- spec/snapshots/namespace_folders.snap
|
|
683
|
-
- spec/snapshots/namespace_map.snap
|
|
684
|
-
- spec/snapshots/producers_with_key-no-nest.snap
|
|
685
|
-
- spec/snapshots/producers_with_key.snap
|
|
686
677
|
- spec/spec_helper.rb
|
|
687
678
|
- spec/test_helpers_spec.rb
|
|
688
679
|
- spec/utils/db_poller_spec.rb
|
|
@@ -711,7 +702,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
711
702
|
- !ruby/object:Gem::Version
|
|
712
703
|
version: '0'
|
|
713
704
|
requirements: []
|
|
714
|
-
rubygems_version: 4.0.
|
|
705
|
+
rubygems_version: 4.0.10
|
|
715
706
|
specification_version: 4
|
|
716
707
|
summary: Kafka libraries for Ruby.
|
|
717
708
|
test_files: []
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
|
-
|
|
5
|
-
module Deimos
|
|
6
|
-
module SchemaClass
|
|
7
|
-
# Base Class for Schema Classes generated from Avro.
|
|
8
|
-
class Base
|
|
9
|
-
|
|
10
|
-
# @param _args [Array<Object>]
|
|
11
|
-
def initialize(*_args)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Converts the object to a hash which can be used for debugging or comparing objects.
|
|
15
|
-
# @param _opts [Hash]
|
|
16
|
-
# @return [Hash] a hash representation of the payload
|
|
17
|
-
def as_json(_opts={})
|
|
18
|
-
raise MissingImplementationError
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# @param key [String,Symbol]
|
|
22
|
-
# @param val [Object]
|
|
23
|
-
# @return [void]
|
|
24
|
-
def []=(key, val)
|
|
25
|
-
self.send("#{key}=", val)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# @param other [SchemaClass::Base]
|
|
29
|
-
# @return [Boolean]
|
|
30
|
-
def ==(other)
|
|
31
|
-
comparison = other
|
|
32
|
-
if other.class == self.class
|
|
33
|
-
comparison = other.as_json
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
comparison == self.as_json
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
alias_method :eql?, :==
|
|
40
|
-
|
|
41
|
-
# @return [String]
|
|
42
|
-
def inspect
|
|
43
|
-
klass = self.class
|
|
44
|
-
"#{klass}(#{self.as_json})"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Initializes this class from a given value
|
|
48
|
-
# @param value [Object]
|
|
49
|
-
# @return [SchemaClass::Base]
|
|
50
|
-
def self.initialize_from_value(_value)
|
|
51
|
-
raise MissingImplementationError
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
protected
|
|
55
|
-
|
|
56
|
-
# @return [Integer]
|
|
57
|
-
def hash
|
|
58
|
-
as_json.hash
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'base'
|
|
4
|
-
require 'json'
|
|
5
|
-
|
|
6
|
-
module Deimos
|
|
7
|
-
module SchemaClass
|
|
8
|
-
# Base Class for Enum Classes generated from Avro.
|
|
9
|
-
class Enum < Base
|
|
10
|
-
|
|
11
|
-
# @return [String]
|
|
12
|
-
attr_accessor :value
|
|
13
|
-
|
|
14
|
-
# @param other [Deimos::SchemaClass::Enum]
|
|
15
|
-
# @return [Boolean]
|
|
16
|
-
def ==(other)
|
|
17
|
-
other.is_a?(self.class) ? other.value == @value : other == @value
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# @return [String]
|
|
21
|
-
def to_s
|
|
22
|
-
@value.to_s
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# @param value [String]
|
|
26
|
-
def initialize(value)
|
|
27
|
-
@value = value
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Returns all the valid symbols for this enum.
|
|
31
|
-
# @return [Array<String>]
|
|
32
|
-
def symbols
|
|
33
|
-
raise MissingImplementationError
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# @return [String]
|
|
37
|
-
def as_json(_opts={})
|
|
38
|
-
@value
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# @return [SchemaClass::Enum]
|
|
42
|
-
def self.initialize_from_value(value, from_message: false)
|
|
43
|
-
return nil if value.nil?
|
|
44
|
-
|
|
45
|
-
value.is_a?(self) ? value : self.new(value)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'base'
|
|
4
|
-
require 'json'
|
|
5
|
-
|
|
6
|
-
module Deimos
|
|
7
|
-
module SchemaClass
|
|
8
|
-
# Base Class of Record Classes generated from Avro.
|
|
9
|
-
class Record < Base
|
|
10
|
-
|
|
11
|
-
attr_accessor :tombstone_key, :_from_message
|
|
12
|
-
|
|
13
|
-
# Converts the object attributes to a hash which can be used for Kafka
|
|
14
|
-
# @return [Hash] the payload as a hash.
|
|
15
|
-
def to_h
|
|
16
|
-
if self.tombstone_key
|
|
17
|
-
{ payload_key: self.tombstone_key&.as_json }
|
|
18
|
-
else
|
|
19
|
-
self.as_json
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Merge a hash or an identical schema object with this one and return a new object.
|
|
24
|
-
# @param other_hash [Hash,SchemaClass::Base]
|
|
25
|
-
# @return [SchemaClass::Base]
|
|
26
|
-
def merge(other_hash)
|
|
27
|
-
obj = self.class.new(**self.to_h.symbolize_keys)
|
|
28
|
-
other_hash.to_h.each do |k, v|
|
|
29
|
-
obj.send("#{k}=", v)
|
|
30
|
-
end
|
|
31
|
-
obj
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Element access method as if this Object were a hash
|
|
35
|
-
# @param key[String,Symbol]
|
|
36
|
-
# @return [Object] The value of the attribute if exists, nil otherwise
|
|
37
|
-
def [](key)
|
|
38
|
-
self.try(key.to_sym)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# @return [SchemaClass::Record]
|
|
42
|
-
def with_indifferent_access
|
|
43
|
-
self
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Returns the schema name of the inheriting class.
|
|
47
|
-
# @return [String]
|
|
48
|
-
def schema
|
|
49
|
-
raise MissingImplementationError
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Returns the namespace for the schema of the inheriting class.
|
|
53
|
-
# @return [String]
|
|
54
|
-
def namespace
|
|
55
|
-
raise MissingImplementationError
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Returns the full schema name of the inheriting class.
|
|
59
|
-
# @return [String]
|
|
60
|
-
def full_schema
|
|
61
|
-
"#{namespace}.#{schema}"
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Returns the schema validator from the schema backend
|
|
65
|
-
# @return [Deimos::SchemaBackends::Base]
|
|
66
|
-
def validator
|
|
67
|
-
Deimos.schema_backend(schema: schema, namespace: namespace)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# @return [Array<String>] an array of fields names in the schema.
|
|
71
|
-
def schema_fields
|
|
72
|
-
validator.schema_fields.map(&:name)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Used internally within Deimos so that we don't crash on unknown fields that come from
|
|
76
|
-
# a backwards compatible schema.
|
|
77
|
-
# @param kwargs [Hash] the attributes to set on the new object.
|
|
78
|
-
# @return [SchemaClass::Record]
|
|
79
|
-
def self.new_from_message(**kwargs)
|
|
80
|
-
record = self.new
|
|
81
|
-
attrs = kwargs.select { |k, _v| record.respond_to?("#{k}=") }
|
|
82
|
-
self.new(_from_message: true, **attrs)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# @return [SchemaClass::Record]
|
|
86
|
-
# @param from_message [Boolean] whether it's being initialized from a real Avro message.
|
|
87
|
-
def self.initialize_from_value(value, from_message: false)
|
|
88
|
-
return nil if value.nil?
|
|
89
|
-
|
|
90
|
-
return value if value.is_a?(self)
|
|
91
|
-
|
|
92
|
-
if from_message
|
|
93
|
-
self.new_from_message(**value&.symbolize_keys || {})
|
|
94
|
-
else
|
|
95
|
-
self.new(**value&.symbolize_keys || {})
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Autogenerated Schema for Enum at <%= @current_schema.namespace %>.<%= @current_schema.name %>
|
|
2
|
-
class <%= Deimos::SchemaBackends::AvroBase.schema_classname(@current_schema) %> < Deimos::SchemaClass::Enum
|
|
3
|
-
# @override
|
|
4
|
-
def symbols
|
|
5
|
-
%w(<%= @current_schema.symbols.join(' ') %>)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
<% @current_schema.symbols.each do |symbol| %>
|
|
9
|
-
def <%= symbol.underscore %>?
|
|
10
|
-
@value == '<%= symbol %>'
|
|
11
|
-
end
|
|
12
|
-
<% end %>
|
|
13
|
-
end
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# Autogenerated Schema for Record at <%= @current_schema.namespace %>.<%= @current_schema.name %>
|
|
2
|
-
class <%= Deimos::SchemaBackends::AvroBase.schema_classname(@current_schema) %> < Deimos::SchemaClass::Record
|
|
3
|
-
<% if @sub_schema_templates.present? -%>
|
|
4
|
-
|
|
5
|
-
### Secondary Schema Classes ###
|
|
6
|
-
<%- @sub_schema_templates.each do |schema_template| -%>
|
|
7
|
-
<%=- schema_template.gsub(/^/, " ") %>
|
|
8
|
-
|
|
9
|
-
<%- end -%>
|
|
10
|
-
<% end -%>
|
|
11
|
-
|
|
12
|
-
<%- if @field_assignments.select{ |h| h[:is_schema_class] }.any? -%>
|
|
13
|
-
### Attribute Readers ###
|
|
14
|
-
<%- @field_assignments.select{ |h| h[:is_schema_class] }.each do |method_definition| -%>
|
|
15
|
-
# @return [<%= method_definition[:deimos_type] %>]
|
|
16
|
-
attr_reader :<%= method_definition[:field].name %>
|
|
17
|
-
<%- end -%>
|
|
18
|
-
|
|
19
|
-
<% end -%>
|
|
20
|
-
<%- if @field_assignments.select{ |h| !h[:is_schema_class] }.any? -%>
|
|
21
|
-
### Attribute Accessors ###
|
|
22
|
-
<%- @field_assignments.select{ |h| !h[:is_schema_class] }.each do |method_definition| -%>
|
|
23
|
-
# @return [<%= method_definition[:deimos_type] %>]
|
|
24
|
-
attr_accessor :<%= method_definition[:field].name %>
|
|
25
|
-
<%- end -%>
|
|
26
|
-
|
|
27
|
-
<% end -%>
|
|
28
|
-
<%- if @field_assignments.select{ |h| h[:is_schema_class] }.any? -%>
|
|
29
|
-
### Attribute Writers ###
|
|
30
|
-
<%- @field_assignments.select{ |h| h[:is_schema_class] }.each do |method_definition| -%>
|
|
31
|
-
# @return [<%= method_definition[:deimos_type] %>]
|
|
32
|
-
def <%= method_definition[:field].name %>=(<%= method_definition[:method_argument] %>)
|
|
33
|
-
<%- if method_definition[:field_type] == :array -%>
|
|
34
|
-
@<%= method_definition[:field].name %> = values&.map do |value|
|
|
35
|
-
<%= method_definition[:field_initialization] %>
|
|
36
|
-
end
|
|
37
|
-
<%- elsif method_definition[:field_type] == :map -%>
|
|
38
|
-
@<%= method_definition[:field].name %> = values&.transform_values do |value|
|
|
39
|
-
<%= method_definition[:field_initialization] %>
|
|
40
|
-
end
|
|
41
|
-
<%- else -%>
|
|
42
|
-
@<%= method_definition[:field].name %> = <%= method_definition[:field_initialization] %>
|
|
43
|
-
<%- end -%>
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
<%- end -%>
|
|
47
|
-
<% end -%>
|
|
48
|
-
<%- if @field_assignments.select{ |h| h[:is_complex_union] }.any? -%>
|
|
49
|
-
<%- @field_assignments.select{ |h| h[:is_complex_union] }.each do |method_definition| -%>
|
|
50
|
-
# Helper method to determine which schema type to use for <%= method_definition[:field].name %>
|
|
51
|
-
# @param value [Hash, nil]
|
|
52
|
-
# @param from_message [Boolean] whether this was initialized from a real Avro message
|
|
53
|
-
# @return [Object, nil]
|
|
54
|
-
def initialize_<%= method_definition[:field].name %>_type(value, from_message: false)
|
|
55
|
-
return nil if value.nil?
|
|
56
|
-
|
|
57
|
-
klass = [<%= method_definition[:field].type.schemas.reject { |s| s.type_sym == :null }.select { |s| s.type_sym == :record }.map { |s| Deimos::SchemaBackends::AvroBase.schema_classname(s) }.join(', ') %>].find do |candidate|
|
|
58
|
-
fields = candidate.new.as_json.keys
|
|
59
|
-
(value.keys - fields).empty?
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
klass.initialize_from_value(value, from_message: self._from_message)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
<%- end -%>
|
|
66
|
-
<% end -%>
|
|
67
|
-
# @override
|
|
68
|
-
<%= @initialization_definition %>
|
|
69
|
-
@_from_message = _from_message
|
|
70
|
-
super
|
|
71
|
-
<%- @fields.each do |field| -%>
|
|
72
|
-
self.<%= field.name %> = <%= field.name %>
|
|
73
|
-
<% end -%>
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# @override
|
|
77
|
-
def schema
|
|
78
|
-
'<%= @current_schema.name %>'
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# @override
|
|
82
|
-
def namespace
|
|
83
|
-
'<%= @current_schema.namespace %>'
|
|
84
|
-
end
|
|
85
|
-
<%- if @tombstone_assignment %>
|
|
86
|
-
def self.tombstone(key)
|
|
87
|
-
record = self.allocate
|
|
88
|
-
<%- if @tombstone_assignment.present? -%>
|
|
89
|
-
<%= @tombstone_assignment %>
|
|
90
|
-
<%- end -%>
|
|
91
|
-
record
|
|
92
|
-
end
|
|
93
|
-
<%- end %>
|
|
94
|
-
# @override
|
|
95
|
-
def as_json(_opts={})
|
|
96
|
-
{
|
|
97
|
-
<%- @fields.each do |field| -%>
|
|
98
|
-
<%= field_as_json(field) %>
|
|
99
|
-
<% end -%>
|
|
100
|
-
}
|
|
101
|
-
end
|
|
102
|
-
end
|