avromatic 0.12.0 → 0.13.0.rc0
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/model/message_decoder.rb +27 -9
- data/lib/avromatic/model/messaging_serialization.rb +5 -1
- data/lib/avromatic/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb91ebe436010bcfd294833c9dcb9262d8e3a87
|
4
|
+
data.tar.gz: 526045c30e99b1a99cbcb1811245f68f80dab7ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84cd59251cc8b0b28461532e9bc352680a5ecc6107f4debbc0de407e62fc889b7e245bc301c18230527e306520dea3cec0764f9e4145fc05ac32384df5ddc216
|
7
|
+
data.tar.gz: b81505c03ae2165854abcef2d31576cdb1f3cbcafaabcfa303999f3f9632dd1d4842632249c1ca1f43f80bae731ac1bb5b5b2f65e010974c6bfa8081cfdb42e5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# avromatic changelog
|
2
2
|
|
3
|
+
## v0.13.0
|
4
|
+
- Add interfaces to deserialize as a hash of attributes instead of a model.
|
5
|
+
|
3
6
|
## v0.12.0
|
4
7
|
- Clear the schema store, if it supports it, prior to code reloading in Rails
|
5
8
|
applications. This allows schema changes to be picked up during code
|
@@ -47,24 +47,42 @@ module Avromatic
|
|
47
47
|
Avromatic.build_schema_registry
|
48
48
|
end
|
49
49
|
|
50
|
-
# If two arguments are specified then the first is interpreted as the
|
51
|
-
# message key and the second is the message value. If there is only one
|
52
|
-
# arg then it is used as the message value.
|
53
50
|
# @return [Avromatic model]
|
54
51
|
def decode(*args)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
with_decode_args(*args) do |model, message_key, message_value|
|
53
|
+
model.avro_message_decode(message_key, message_value)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Hash]
|
58
|
+
def decode_hash(*args)
|
59
|
+
with_decode_args(*args) do |model, message_key, message_value|
|
60
|
+
model.avro_message_attributes(message_key, message_value)
|
61
|
+
end
|
59
62
|
end
|
60
63
|
|
61
64
|
private
|
62
65
|
|
63
66
|
attr_reader :schema_names_by_id, :model_map, :schema_registry
|
64
67
|
|
65
|
-
def
|
68
|
+
def extract_key_and_value(*args)
|
69
|
+
args.size > 1 ? args.take(2) : [nil, args.first]
|
70
|
+
end
|
71
|
+
|
72
|
+
def model_key_for_message(message_key, message_value)
|
73
|
+
value_schema_name = schema_name_for_data(message_value)
|
74
|
+
key_schema_name = schema_name_for_data(message_key) if message_key
|
75
|
+
[key_schema_name, value_schema_name]
|
76
|
+
end
|
77
|
+
|
78
|
+
# If two arguments are specified then the first is interpreted as the
|
79
|
+
# message key and the second is the message value. If there is only one
|
80
|
+
# arg then it is used as the message value.
|
81
|
+
def with_decode_args(*args)
|
82
|
+
message_key, message_value = extract_key_and_value(*args)
|
83
|
+
model_key = model_key_for_message(message_key, message_value)
|
66
84
|
raise UnexpectedKeyError.new(model_key) unless model_map.key?(model_key)
|
67
|
-
model_map[model_key]
|
85
|
+
yield(model_map[model_key], message_key, message_value)
|
68
86
|
end
|
69
87
|
|
70
88
|
def schema_name_for_data(data)
|
@@ -38,13 +38,17 @@ module Avromatic
|
|
38
38
|
# message key and the second is the message value. If there is only one
|
39
39
|
# arg then it is used as the message value.
|
40
40
|
def avro_message_decode(*args)
|
41
|
+
new(avro_message_attributes(*args))
|
42
|
+
end
|
43
|
+
|
44
|
+
def avro_message_attributes(*args)
|
41
45
|
message_key, message_value = args.size > 1 ? args : [nil, args.first]
|
42
46
|
key_attributes = message_key &&
|
43
47
|
avro_messaging.decode(message_key, schema_name: key_avro_schema.fullname)
|
44
48
|
value_attributes = avro_messaging
|
45
49
|
.decode(message_value, schema_name: avro_schema.fullname)
|
46
50
|
|
47
|
-
|
51
|
+
value_attributes.merge!(key_attributes || {})
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
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.13.0.rc0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|
@@ -287,12 +287,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
287
287
|
version: '0'
|
288
288
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
289
289
|
requirements:
|
290
|
-
- - "
|
290
|
+
- - ">"
|
291
291
|
- !ruby/object:Gem::Version
|
292
|
-
version:
|
292
|
+
version: 1.3.1
|
293
293
|
requirements: []
|
294
294
|
rubyforge_project:
|
295
|
-
rubygems_version: 2.
|
295
|
+
rubygems_version: 2.6.8
|
296
296
|
signing_key:
|
297
297
|
specification_version: 4
|
298
298
|
summary: Generate Ruby models from Avro schemas
|