avromatic 0.27.0 → 0.28.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +5 -4
- data/lib/avromatic.rb +5 -0
- data/lib/avromatic/io.rb +1 -0
- data/lib/avromatic/io/datum_writer.rb +8 -0
- data/lib/avromatic/model/raw_serialization.rb +10 -1
- data/lib/avromatic/patches.rb +11 -0
- data/lib/avromatic/patches/schema_validator_patch.rb +20 -0
- data/lib/avromatic/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 361781d979e68fb4b48f288153368b9d2f00d064
|
4
|
+
data.tar.gz: d761359438529abe3ca428582c68d47a73de7587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15122e83c1a2f3301d25873f56a668b1bd545bb5e3763bc0d56d2c1135ed812961ef786da27ca16eaaef1d3864cea2f2f6d481fc36f5829f9347e692fac91f1e
|
7
|
+
data.tar.gz: 10e242e0cc4f755992d1b955ea9e5ab6746be6c30b60d79277f96e121e44b807a96bb1a79b1a22290fd1d525a73932b48dd64b54b348ad99a4d09ff3d866fbf1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# avromatic changelog
|
2
2
|
|
3
|
+
## v0.28.1
|
4
|
+
- Fix a bug that raised an error when encoding a cached model containing optional
|
5
|
+
field(s). With this change, immutable model caching now enabled only when
|
6
|
+
`avro-patches` is present.
|
7
|
+
|
8
|
+
## v0.28.0
|
9
|
+
- Add support for caching avro encodings for immutable models
|
10
|
+
|
3
11
|
## v0.27.0
|
4
12
|
- Patches avromatic model classes to cache `Virtus::ValueObject::AllowedWriterMethods#allowed_writer_methods`
|
5
13
|
- Support Rails 5.1
|
data/README.md
CHANGED
@@ -99,10 +99,11 @@ end
|
|
99
99
|
|
100
100
|
#### Encoding
|
101
101
|
* **use_custom_datum_writer**: `Avromatic` includes a modified subclass of
|
102
|
-
`Avro::IO::DatumWriter`. This subclass
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
`Avro::IO::DatumWriter`. This subclass supports caching avro encodings for
|
103
|
+
immutable models and uses additional information about the index of union
|
104
|
+
members to optimize the encoding of Avro messages. By default this
|
105
|
+
information is included in the hash passed to the encoder but can be omitted
|
106
|
+
by setting this option to `false`.
|
106
107
|
|
107
108
|
|
108
109
|
### Models
|
data/lib/avromatic.rb
CHANGED
@@ -4,6 +4,7 @@ require 'avromatic/model'
|
|
4
4
|
require 'avromatic/model_registry'
|
5
5
|
require 'avromatic/messaging'
|
6
6
|
require 'active_support/core_ext/string/inflections'
|
7
|
+
require 'avromatic/patches'
|
7
8
|
|
8
9
|
module Avromatic
|
9
10
|
class << self
|
@@ -27,6 +28,10 @@ module Avromatic
|
|
27
28
|
eager_load_models!
|
28
29
|
end
|
29
30
|
|
31
|
+
def self.use_encoding_providers?
|
32
|
+
use_custom_datum_writer && defined?(Avromatic::Patches::SchemaValidatorPatch)
|
33
|
+
end
|
34
|
+
|
30
35
|
def self.build_schema_registry
|
31
36
|
raise 'Avromatic must be configured with a registry_url' unless registry_url
|
32
37
|
if use_schema_fingerprint_lookup
|
data/lib/avromatic/io.rb
CHANGED
@@ -20,6 +20,14 @@ module Avromatic
|
|
20
20
|
encoder.write_long(index_of_schema)
|
21
21
|
write_data(writers_schema.schemas[index_of_schema], datum, encoder)
|
22
22
|
end
|
23
|
+
|
24
|
+
def write_record(writers_schema, datum, encoder)
|
25
|
+
if datum.is_a?(Hash) && datum.key?(Avromatic::IO::ENCODING_PROVIDER)
|
26
|
+
encoder.write(datum[Avromatic::IO::ENCODING_PROVIDER].avro_raw_value)
|
27
|
+
else
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
@@ -29,6 +29,11 @@ module Avromatic
|
|
29
29
|
if value.is_a?(Avromatic::Model::Attributes)
|
30
30
|
hash = value.value_attributes_for_avro
|
31
31
|
if Avromatic.use_custom_datum_writer
|
32
|
+
if Avromatic.use_encoding_providers? && !value.class.config.mutable
|
33
|
+
# n.b. Ideally we'd just return value here instead of wrapping it in a
|
34
|
+
# hash but then we'd have no place to stash the union member index...
|
35
|
+
hash = { Avromatic::IO::ENCODING_PROVIDER => value }
|
36
|
+
end
|
32
37
|
member_index = member_types.index(value.class) if member_types.any?
|
33
38
|
hash[Avromatic::IO::UNION_MEMBER_INDEX] = member_index if member_index
|
34
39
|
end
|
@@ -67,7 +72,11 @@ module Avromatic
|
|
67
72
|
end
|
68
73
|
|
69
74
|
def avro_raw_value
|
70
|
-
|
75
|
+
if self.class.config.mutable
|
76
|
+
avro_raw_encode(value_attributes_for_avro, :value)
|
77
|
+
else
|
78
|
+
@avro_raw_value ||= avro_raw_encode(value_attributes_for_avro, :value)
|
79
|
+
end
|
71
80
|
end
|
72
81
|
|
73
82
|
def avro_raw_key
|
@@ -0,0 +1,11 @@
|
|
1
|
+
loaded_avro_patches = begin
|
2
|
+
require 'avro-patches'
|
3
|
+
true
|
4
|
+
rescue LoadError
|
5
|
+
false
|
6
|
+
end
|
7
|
+
|
8
|
+
if loaded_avro_patches
|
9
|
+
require 'avromatic/patches/schema_validator_patch'
|
10
|
+
Avro::SchemaValidator.singleton_class.prepend(Avromatic::Patches::SchemaValidatorPatch)
|
11
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Avromatic
|
2
|
+
module Patches
|
3
|
+
module SchemaValidatorPatch
|
4
|
+
# This method replaces validate_recursive in AvroPatches::LogicalTypes::SchemaValidatorPatch
|
5
|
+
# to enable validating datums that contain an encoding provider.
|
6
|
+
def validate_recursive(expected_schema, logical_datum, path, result, encoded = false)
|
7
|
+
datum = resolve_datum(expected_schema, logical_datum, encoded)
|
8
|
+
case expected_schema.type_sym
|
9
|
+
when :record, :error, :request
|
10
|
+
if datum.is_a?(Hash) && datum.key?(Avromatic::IO::ENCODING_PROVIDER)
|
11
|
+
return if expected_schema.sha256_resolution_fingerprint ==
|
12
|
+
datum[Avromatic::IO::ENCODING_PROVIDER].value_avro_schema.sha256_resolution_fingerprint
|
13
|
+
raise Avro::SchemaValidator::ValidationError
|
14
|
+
end
|
15
|
+
end
|
16
|
+
super(expected_schema, logical_datum, path, result, encoded)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
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: 0.
|
4
|
+
version: 0.28.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|
@@ -304,6 +304,8 @@ files:
|
|
304
304
|
- lib/avromatic/model/validation.rb
|
305
305
|
- lib/avromatic/model/value_object.rb
|
306
306
|
- lib/avromatic/model_registry.rb
|
307
|
+
- lib/avromatic/patches.rb
|
308
|
+
- lib/avromatic/patches/schema_validator_patch.rb
|
307
309
|
- lib/avromatic/railtie.rb
|
308
310
|
- lib/avromatic/rspec.rb
|
309
311
|
- lib/avromatic/version.rb
|