avromatic 0.12.0 → 0.13.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7486e17a66fe4b7450e882c2a20690101b29649b
4
- data.tar.gz: 7ae8899bfd60939a3f2bda6c87eb09c5eaf4f188
3
+ metadata.gz: 6bb91ebe436010bcfd294833c9dcb9262d8e3a87
4
+ data.tar.gz: 526045c30e99b1a99cbcb1811245f68f80dab7ba
5
5
  SHA512:
6
- metadata.gz: f8f43c783dfea0f33cd0f2b696a241e5756d5a74e552d6fe25f4372669d86b4c0977a808996b170d4d5b75e6ad25cb5887b9cc220aaa68bf64640e4857af18a3
7
- data.tar.gz: 94a15788ff81fc4f065188d521813325b91c87e1f88a21bb536f786f32daf0dff3da3e5e290b28a65ea98e67f815f365fd3851134ec5165b5affca1e4dd0ac71
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
- message_key, message_value = args.size > 1 ? args : [nil, args.first]
56
- value_schema_name = schema_name_for_data(message_value)
57
- key_schema_name = schema_name_for_data(message_key) if message_key
58
- deserialize([key_schema_name, value_schema_name], message_key, message_value)
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 deserialize(model_key, message_key, message_value)
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].avro_message_decode(message_key, message_value)
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
- new(value_attributes.merge!(key_attributes || {}))
51
+ value_attributes.merge!(key_attributes || {})
48
52
  end
49
53
  end
50
54
 
@@ -1,3 +1,3 @@
1
1
  module Avromatic
2
- VERSION = '0.12.0'.freeze
2
+ VERSION = '0.13.0.rc0'.freeze
3
3
  end
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.12.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: 2016-11-10 00:00:00.000000000 Z
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: '0'
292
+ version: 1.3.1
293
293
  requirements: []
294
294
  rubyforge_project:
295
- rubygems_version: 2.4.8
295
+ rubygems_version: 2.6.8
296
296
  signing_key:
297
297
  specification_version: 4
298
298
  summary: Generate Ruby models from Avro schemas