avromatic 2.2.5 → 2.2.6
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 +3 -0
- data/lib/avromatic/io/datum_writer.rb +0 -6
- data/lib/avromatic/model/configurable.rb +24 -0
- data/lib/avromatic/model/raw_serialization.rb +11 -11
- 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: 5038f6f83ba2ca87bc8cd16a96aae5528397ca5cf9ef01d955861459ae68391a
|
4
|
+
data.tar.gz: 83f5e8bb53086297882f77108480976292a2ca97b40dcb3da5a23c579a7c1edd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d5f8501fc5e050db26475ea1205a1c08f864d6fae8272e54c4a04df4fb22bf634868dadde7eade371a6b22f5438423f84a6405808286b1c687fb7acb26859c3
|
7
|
+
data.tar.gz: 7025885a25ab59923d8efc08e494a51f3c6bc57f0e72eedc84c00b9b46c1ef1df085d99ba9135d6997a8370f3fb1497690a714ca067896faad1a2e9a25f0e970
|
data/CHANGELOG.md
CHANGED
@@ -5,10 +5,6 @@ module Avromatic
|
|
5
5
|
# Subclass DatumWriter to use additional information about union member
|
6
6
|
# index.
|
7
7
|
class DatumWriter < Avro::IO::DatumWriter
|
8
|
-
class << self
|
9
|
-
attr_accessor :optimize
|
10
|
-
end
|
11
|
-
|
12
8
|
def write_union(writers_schema, datum, encoder)
|
13
9
|
optional = writers_schema.schemas.first.type_sym == :null
|
14
10
|
if datum.is_a?(Hash) && datum.key?(Avromatic::IO::UNION_MEMBER_INDEX)
|
@@ -18,8 +14,6 @@ module Avromatic
|
|
18
14
|
elsif optional && writers_schema.schemas.size == 2
|
19
15
|
# Optimize for the common case of a union that's just an optional field
|
20
16
|
index_of_schema = datum.nil? ? 0 : 1
|
21
|
-
elsif self.class.optimize && optional && datum.nil?
|
22
|
-
index_of_schema = 0
|
23
17
|
else
|
24
18
|
index_of_schema = writers_schema.schemas.find_index do |schema|
|
25
19
|
Avro::Schema.validate(schema, datum)
|
@@ -8,6 +8,17 @@ module Avromatic
|
|
8
8
|
module Configurable
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
|
+
# Wraps a reference to a field so we can access both the string and symbolized versions of the name
|
12
|
+
# without repeated memory allocations.
|
13
|
+
class FieldReference
|
14
|
+
attr_reader :name, :name_sym
|
15
|
+
|
16
|
+
def initialize(name)
|
17
|
+
@name = -name
|
18
|
+
@name_sym = name.to_sym
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
11
22
|
module ClassMethods
|
12
23
|
attr_accessor :config
|
13
24
|
delegate :avro_schema, :value_avro_schema, :key_avro_schema, to: :config
|
@@ -20,6 +31,18 @@ module Avromatic
|
|
20
31
|
@key_avro_field_names ||= key_avro_schema.fields.map(&:name).map(&:to_sym).freeze
|
21
32
|
end
|
22
33
|
|
34
|
+
def value_avro_field_references
|
35
|
+
@value_avro_field_references ||= value_avro_schema.fields.map do |field|
|
36
|
+
Avromatic::Model::Configurable::FieldReference.new(field.name)
|
37
|
+
end.freeze
|
38
|
+
end
|
39
|
+
|
40
|
+
def key_avro_field_references
|
41
|
+
@key_avro_field_references ||= key_avro_schema.fields.map do |field|
|
42
|
+
Avromatic::Model::Configurable::FieldReference.new(field.name)
|
43
|
+
end.freeze
|
44
|
+
end
|
45
|
+
|
23
46
|
def value_avro_fields_by_name
|
24
47
|
@value_avro_fields_by_name ||= mapped_by_name(value_avro_schema)
|
25
48
|
end
|
@@ -43,6 +66,7 @@ module Avromatic
|
|
43
66
|
|
44
67
|
delegate :avro_schema, :value_avro_schema, :key_avro_schema,
|
45
68
|
:value_avro_field_names, :key_avro_field_names,
|
69
|
+
:value_avro_field_references, :key_avro_field_references,
|
46
70
|
to: :class
|
47
71
|
end
|
48
72
|
end
|
@@ -29,37 +29,37 @@ module Avromatic
|
|
29
29
|
|
30
30
|
def value_attributes_for_avro(validate: true)
|
31
31
|
if self.class.config.mutable
|
32
|
-
avro_hash(
|
32
|
+
avro_hash(value_avro_field_references, validate: validate)
|
33
33
|
else
|
34
|
-
@value_attributes_for_avro ||= avro_hash(
|
34
|
+
@value_attributes_for_avro ||= avro_hash(value_avro_field_references, validate: validate)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def key_attributes_for_avro(validate: true)
|
39
|
-
avro_hash(
|
39
|
+
avro_hash(key_avro_field_references, validate: validate)
|
40
40
|
end
|
41
41
|
|
42
42
|
def avro_value_datum(validate: true)
|
43
43
|
if self.class.config.mutable
|
44
|
-
avro_hash(
|
44
|
+
avro_hash(value_avro_field_references, strict: true, validate: validate)
|
45
45
|
else
|
46
|
-
@avro_datum ||= avro_hash(
|
46
|
+
@avro_datum ||= avro_hash(value_avro_field_references, strict: true, validate: validate)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def avro_key_datum(validate: true)
|
51
|
-
avro_hash(
|
51
|
+
avro_hash(key_avro_field_references, strict: true, validate: validate)
|
52
52
|
end
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
-
def avro_hash(
|
56
|
+
def avro_hash(field_references, strict: false, validate:)
|
57
57
|
avro_validate! if validate
|
58
|
-
|
59
|
-
next unless _attributes.include?(
|
58
|
+
field_references.each_with_object(Hash.new) do |field_reference, result|
|
59
|
+
next unless _attributes.include?(field_reference.name_sym)
|
60
60
|
|
61
|
-
value = _attributes[
|
62
|
-
result[
|
61
|
+
value = _attributes[field_reference.name_sym]
|
62
|
+
result[field_reference.name] = attribute_definitions[field_reference.name_sym].serialize(value, strict)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
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: 2.2.
|
4
|
+
version: 2.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|