avromatic 2.2.4 → 2.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/avromatic/io/datum_reader.rb +1 -1
- data/lib/avromatic/io/datum_writer.rb +6 -0
- data/lib/avromatic/model/attributes.rb +6 -6
- data/lib/avromatic/model/raw_serialization.rb +5 -2
- data/lib/avromatic/model/types/abstract_timestamp_type.rb +1 -1
- data/lib/avromatic/model/types/abstract_type.rb +3 -1
- data/lib/avromatic/model/types/array_type.rb +2 -2
- data/lib/avromatic/model/types/boolean_type.rb +1 -1
- data/lib/avromatic/model/types/custom_type.rb +1 -1
- data/lib/avromatic/model/types/date_type.rb +1 -1
- data/lib/avromatic/model/types/enum_type.rb +1 -1
- data/lib/avromatic/model/types/fixed_type.rb +1 -1
- data/lib/avromatic/model/types/float_type.rb +1 -1
- data/lib/avromatic/model/types/integer_type.rb +1 -1
- data/lib/avromatic/model/types/map_type.rb +2 -2
- data/lib/avromatic/model/types/null_type.rb +1 -1
- data/lib/avromatic/model/types/record_type.rb +1 -1
- data/lib/avromatic/model/types/string_type.rb +1 -1
- data/lib/avromatic/model/types/union_type.rb +2 -2
- data/lib/avromatic/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdd13d41971f1b38c3b1a9496ec698a14122b69ed5442b4cca7ac7e7d099c6b2
|
4
|
+
data.tar.gz: af4fbf880781abeffc7e0807491ca43a0fdabdff5714c60bfe46b365caa355a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 856111e8a1f7e5ec99cbbe20877095ff630182f27265617e7746437402e4146628c5ae2812f85a9f0cd5c234b748bd1b1c8abee8fddb92e21bc137537074a0d4
|
7
|
+
data.tar.gz: 275aa990b3a84aaa679141955a93800cb4764fc0bbf44a290cbaebd4d54e1cd443f2a3943431b2781bcc6165df06861c7a0d6f9c6bf4c754732737518935d896
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -142,7 +142,7 @@ instance.eql?(MyModel.new(id: 123, name: 'Tesla Model 3', enabled: true)) # => t
|
|
142
142
|
instance.hash # => -1279155042741869898
|
143
143
|
|
144
144
|
# Retrieve a hash of the model's attributes via to_h, to_hash or attributes
|
145
|
-
instance
|
145
|
+
instance.to_h # => {:id=>123, :name=>"Tesla Model 3", :enabled=>true}
|
146
146
|
```
|
147
147
|
|
148
148
|
Or an `Avro::Schema` object can be specified directly:
|
@@ -25,7 +25,7 @@ module Avromatic
|
|
25
25
|
optional = readers_schema.schemas.first.type_sym == :null
|
26
26
|
union_info = if readers_schema.schemas.size == 2 && optional
|
27
27
|
# Avromatic does not treat the union of null and 1 other type as a union
|
28
|
-
|
28
|
+
nil
|
29
29
|
elsif optional
|
30
30
|
# Avromatic does not treat the null of an optional field as part of the union
|
31
31
|
{ UNION_MEMBER_INDEX => rs_index - 1 }
|
@@ -5,6 +5,10 @@ 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
|
+
|
8
12
|
def write_union(writers_schema, datum, encoder)
|
9
13
|
optional = writers_schema.schemas.first.type_sym == :null
|
10
14
|
if datum.is_a?(Hash) && datum.key?(Avromatic::IO::UNION_MEMBER_INDEX)
|
@@ -14,6 +18,8 @@ module Avromatic
|
|
14
18
|
elsif optional && writers_schema.schemas.size == 2
|
15
19
|
# Optimize for the common case of a union that's just an optional field
|
16
20
|
index_of_schema = datum.nil? ? 0 : 1
|
21
|
+
elsif self.class.optimize && optional && datum.nil?
|
22
|
+
index_of_schema = 0
|
17
23
|
else
|
18
24
|
index_of_schema = writers_schema.schemas.find_index do |schema|
|
19
25
|
Avro::Schema.validate(schema, datum)
|
@@ -74,23 +74,23 @@ module Avromatic
|
|
74
74
|
def initialize(data = {})
|
75
75
|
super()
|
76
76
|
|
77
|
-
|
77
|
+
num_valid_keys = 0
|
78
78
|
attribute_definitions.each do |attribute_name, attribute_definition|
|
79
79
|
if data.include?(attribute_name)
|
80
|
-
|
80
|
+
num_valid_keys += 1
|
81
81
|
value = data.fetch(attribute_name)
|
82
82
|
send(attribute_definition.setter_name, value)
|
83
83
|
elsif data.include?(attribute_definition.name_string)
|
84
|
-
|
84
|
+
num_valid_keys += 1
|
85
85
|
value = data[attribute_definition.name_string]
|
86
86
|
send(attribute_definition.setter_name, value)
|
87
|
-
elsif !
|
87
|
+
elsif !_attributes.include?(attribute_name)
|
88
88
|
send(attribute_definition.setter_name, attribute_definition.default)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
unless Avromatic.allow_unknown_attributes ||
|
93
|
-
unknown_attributes = (data.keys.map(&:to_s) -
|
92
|
+
unless Avromatic.allow_unknown_attributes || num_valid_keys == data.size
|
93
|
+
unknown_attributes = (data.keys.map(&:to_s) - _attributes.keys.map(&:to_s)).sort
|
94
94
|
allowed_attributes = attribute_definitions.keys.map(&:to_s).sort
|
95
95
|
message = "Unexpected arguments for #{self.class.name}#initialize: #{unknown_attributes.join(', ')}. " \
|
96
96
|
"Only the following arguments are allowed: #{allowed_attributes.join(', ')}. Provided arguments: #{data.inspect}"
|
@@ -55,8 +55,11 @@ module Avromatic
|
|
55
55
|
|
56
56
|
def avro_hash(fields, strict: false, validate:)
|
57
57
|
avro_validate! if validate
|
58
|
-
|
59
|
-
|
58
|
+
fields.each_with_object(Hash.new) do |field, result|
|
59
|
+
next unless _attributes.include?(field)
|
60
|
+
|
61
|
+
value = _attributes[field]
|
62
|
+
result[field.to_s] = attribute_definitions[field].serialize(value, strict)
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
@@ -31,7 +31,9 @@ module Avromatic
|
|
31
31
|
raise "#{__method__} must be overridden by #{self.class.name}"
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
# Note we use positional args rather than keyword args to reduce
|
35
|
+
# memory allocations
|
36
|
+
def serialize(_value, _strict)
|
35
37
|
raise "#{__method__} must be overridden by #{self.class.name}"
|
36
38
|
end
|
37
39
|
|
@@ -40,11 +40,11 @@ module Avromatic
|
|
40
40
|
value.nil? || (value.is_a?(::Array) && value.all? { |element| value_type.coerced?(element) })
|
41
41
|
end
|
42
42
|
|
43
|
-
def serialize(value, strict
|
43
|
+
def serialize(value, strict)
|
44
44
|
if value.nil?
|
45
45
|
value
|
46
46
|
else
|
47
|
-
value.map { |element| value_type.serialize(element, strict
|
47
|
+
value.map { |element| value_type.serialize(element, strict) }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -59,12 +59,12 @@ module Avromatic
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def serialize(value, strict
|
62
|
+
def serialize(value, strict)
|
63
63
|
if value.nil?
|
64
64
|
value
|
65
65
|
else
|
66
66
|
value.each_with_object({}) do |(element_key, element_value), result|
|
67
|
-
result[key_type.serialize(element_key, strict
|
67
|
+
result[key_type.serialize(element_key, strict)] = value_type.serialize(element_value, strict)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -39,7 +39,7 @@ module Avromatic
|
|
39
39
|
value.nil? || value.is_a?(record_class)
|
40
40
|
end
|
41
41
|
|
42
|
-
def serialize(value, strict
|
42
|
+
def serialize(value, strict)
|
43
43
|
if value.nil?
|
44
44
|
value
|
45
45
|
elsif !strict && Avromatic.use_custom_datum_writer && Avromatic.use_encoding_providers? && !record_class.config.mutable
|
@@ -51,7 +51,7 @@ module Avromatic
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def serialize(value, strict
|
54
|
+
def serialize(value, strict)
|
55
55
|
# Avromatic does not treat the null of an optional field as part of the union
|
56
56
|
return nil if value.nil?
|
57
57
|
|
@@ -60,7 +60,7 @@ module Avromatic
|
|
60
60
|
raise ArgumentError.new("Expected #{value.inspect} to be one of #{value_classes.map(&:name)}")
|
61
61
|
end
|
62
62
|
|
63
|
-
hash = member_types[member_index].serialize(value, strict
|
63
|
+
hash = member_types[member_index].serialize(value, strict)
|
64
64
|
if !strict && Avromatic.use_custom_datum_writer && value.is_a?(Avromatic::Model::Attributes)
|
65
65
|
hash[Avromatic::IO::UNION_MEMBER_INDEX] = member_index
|
66
66
|
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: 2.2.
|
4
|
+
version: 2.2.5
|
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-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -349,8 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
349
349
|
- !ruby/object:Gem::Version
|
350
350
|
version: '0'
|
351
351
|
requirements: []
|
352
|
-
|
353
|
-
rubygems_version: 2.7.6.2
|
352
|
+
rubygems_version: 3.0.8
|
354
353
|
signing_key:
|
355
354
|
specification_version: 4
|
356
355
|
summary: Generate Ruby models from Avro schemas
|