avromatic 5.1.0 → 5.2.0
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/lib/avromatic/model/raw_serialization.rb +2 -0
- data/lib/avromatic/model/types/abstract_type.rb +5 -4
- data/lib/avromatic/model/types/array_type.rb +1 -1
- data/lib/avromatic/model/types/big_int_type.rb +49 -0
- data/lib/avromatic/model/types/boolean_type.rb +0 -6
- data/lib/avromatic/model/types/date_type.rb +5 -6
- data/lib/avromatic/model/types/decimal_type.rb +0 -8
- data/lib/avromatic/model/types/enum_type.rb +2 -2
- data/lib/avromatic/model/types/float_type.rb +0 -8
- data/lib/avromatic/model/types/integer_type.rb +8 -2
- data/lib/avromatic/model/types/record_type.rb +0 -4
- data/lib/avromatic/model/types/string_type.rb +0 -8
- data/lib/avromatic/model/types/type_factory.rb +2 -1
- data/lib/avromatic/model/types/union_type.rb +9 -1
- data/lib/avromatic/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2619e37540f7e7f6002c5e51c1d252f7ba7b3cca4beefc22d7a6d6c568c73eba
|
4
|
+
data.tar.gz: c1da85904d906f67aa0f26828672080e91e1358f3079b51645a8d123da9f964e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20ad16e3d4f3f7f36231a1557711df1100ccfd506de38e0bbe8968b8689226805f0a2133c3e8408b03fb44c62844239f88b1b684a720e1bed6fdabc2b9ccea08
|
7
|
+
data.tar.gz: 59a9138f0bb58711800416751cc08858398242251517aa86b8eb86802abe2866e61551714a3eed7622658dbb9a36da60bfdbe521c21d899eb601b104915f84a9
|
@@ -15,8 +15,10 @@ module Avromatic
|
|
15
15
|
|
16
16
|
UNSPECIFIED = Object.new
|
17
17
|
|
18
|
+
# rubocop:disable Style/AccessModifierDeclarations
|
18
19
|
delegate :datum_writer, :datum_reader, to: :class
|
19
20
|
private :datum_writer, :datum_reader
|
21
|
+
# rubocop:enable Style/AccessModifierDeclarations
|
20
22
|
|
21
23
|
def avro_raw_value(validate: UNSPECIFIED)
|
22
24
|
unless validate == UNSPECIFIED
|
@@ -4,6 +4,7 @@ module Avromatic
|
|
4
4
|
module Model
|
5
5
|
module Types
|
6
6
|
class AbstractType
|
7
|
+
|
7
8
|
EMPTY_ARRAY = [].freeze
|
8
9
|
private_constant :EMPTY_ARRAY
|
9
10
|
|
@@ -23,12 +24,12 @@ module Avromatic
|
|
23
24
|
raise "#{__method__} must be overridden by #{self.class.name}"
|
24
25
|
end
|
25
26
|
|
26
|
-
def coercible?(
|
27
|
-
|
27
|
+
def coercible?(input)
|
28
|
+
input.nil? || input_classes.any? { |input_class| input.is_a?(input_class) }
|
28
29
|
end
|
29
30
|
|
30
|
-
def coerced?(
|
31
|
-
|
31
|
+
def coerced?(value)
|
32
|
+
value.nil? || value_classes.any? { |value_class| value.is_a?(value_class) }
|
32
33
|
end
|
33
34
|
|
34
35
|
# Note we use positional args rather than keyword args to reduce
|
@@ -38,7 +38,7 @@ module Avromatic
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def coerced?(value)
|
41
|
-
value.nil? || (value.is_a?(::Array) && value.all? { |
|
41
|
+
value.nil? || (value.is_a?(::Array) && value.all? { |element_input| value_type.coerced?(element_input) })
|
42
42
|
end
|
43
43
|
|
44
44
|
def serialize(value, strict)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avromatic/model/types/abstract_type'
|
4
|
+
|
5
|
+
module Avromatic
|
6
|
+
module Model
|
7
|
+
module Types
|
8
|
+
class BigIntType < AbstractType
|
9
|
+
VALUE_CLASSES = [::Integer].freeze
|
10
|
+
|
11
|
+
MAX_RANGE = 2**63
|
12
|
+
|
13
|
+
def self.in_range?(value)
|
14
|
+
value.is_a?(::Integer) && value.between?(-MAX_RANGE, MAX_RANGE - 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
def value_classes
|
18
|
+
VALUE_CLASSES
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
'bigint'
|
23
|
+
end
|
24
|
+
|
25
|
+
def coerce(input)
|
26
|
+
if coercible?(input)
|
27
|
+
input
|
28
|
+
else
|
29
|
+
raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def coercible?(input)
|
34
|
+
input.nil? || self.class.in_range?(input)
|
35
|
+
end
|
36
|
+
|
37
|
+
alias_method :coerced?, :coercible?
|
38
|
+
|
39
|
+
def serialize(value, _strict)
|
40
|
+
value
|
41
|
+
end
|
42
|
+
|
43
|
+
def referenced_model_classes
|
44
|
+
EMPTY_ARRAY
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -7,11 +7,16 @@ module Avromatic
|
|
7
7
|
module Types
|
8
8
|
class DateType < AbstractType
|
9
9
|
VALUE_CLASSES = [::Date].freeze
|
10
|
+
INPUT_CLASSES = [::Date, ::Time].freeze
|
10
11
|
|
11
12
|
def value_classes
|
12
13
|
VALUE_CLASSES
|
13
14
|
end
|
14
15
|
|
16
|
+
def input_classes
|
17
|
+
INPUT_CLASSES
|
18
|
+
end
|
19
|
+
|
15
20
|
def name
|
16
21
|
'date'
|
17
22
|
end
|
@@ -26,12 +31,6 @@ module Avromatic
|
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
29
|
-
def coercible?(input)
|
30
|
-
input.nil? || input.is_a?(::Date) || input.is_a?(::Time)
|
31
|
-
end
|
32
|
-
|
33
|
-
alias_method :coerced?, :coercible?
|
34
|
-
|
35
34
|
def serialize(value, _strict)
|
36
35
|
value
|
37
36
|
end
|
@@ -42,14 +42,6 @@ module Avromatic
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def coercible?(input)
|
46
|
-
input.nil? || input_classes.any? { |input_class| input.is_a?(input_class) }
|
47
|
-
end
|
48
|
-
|
49
|
-
def coerced?(value)
|
50
|
-
value.nil? || value_classes.any? { |value_class| value.is_a?(value_class) }
|
51
|
-
end
|
52
|
-
|
53
45
|
def serialize(value, _strict)
|
54
46
|
value
|
55
47
|
end
|
@@ -38,8 +38,8 @@ module Avromatic
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def coerced?(
|
42
|
-
|
41
|
+
def coerced?(value)
|
42
|
+
value.nil? || value.is_a?(::String) && allowed_values.include?(value)
|
43
43
|
end
|
44
44
|
|
45
45
|
def coercible?(input)
|
@@ -31,14 +31,6 @@ module Avromatic
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def coercible?(input)
|
35
|
-
input.nil? || input.is_a?(::Float) || input.is_a?(::Integer)
|
36
|
-
end
|
37
|
-
|
38
|
-
def coerced?(input)
|
39
|
-
input.nil? || input.is_a?(::Float)
|
40
|
-
end
|
41
|
-
|
42
34
|
def serialize(value, _strict)
|
43
35
|
value
|
44
36
|
end
|
@@ -8,6 +8,12 @@ module Avromatic
|
|
8
8
|
class IntegerType < AbstractType
|
9
9
|
VALUE_CLASSES = [::Integer].freeze
|
10
10
|
|
11
|
+
MAX_RANGE = 2**31
|
12
|
+
|
13
|
+
def self.in_range?(value)
|
14
|
+
value.is_a?(::Integer) && value.between?(-MAX_RANGE, MAX_RANGE - 1)
|
15
|
+
end
|
16
|
+
|
11
17
|
def value_classes
|
12
18
|
VALUE_CLASSES
|
13
19
|
end
|
@@ -17,7 +23,7 @@ module Avromatic
|
|
17
23
|
end
|
18
24
|
|
19
25
|
def coerce(input)
|
20
|
-
if
|
26
|
+
if coercible?(input)
|
21
27
|
input
|
22
28
|
else
|
23
29
|
raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}")
|
@@ -25,7 +31,7 @@ module Avromatic
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def coercible?(input)
|
28
|
-
input.nil? ||
|
34
|
+
input.nil? || self.class.in_range?(input)
|
29
35
|
end
|
30
36
|
|
31
37
|
alias_method :coerced?, :coercible?
|
@@ -31,14 +31,6 @@ module Avromatic
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def coercible?(input)
|
35
|
-
input.nil? || input.is_a?(::String) || input.is_a?(::Symbol)
|
36
|
-
end
|
37
|
-
|
38
|
-
def coerced?(value)
|
39
|
-
value.nil? || value.is_a?(::String)
|
40
|
-
end
|
41
|
-
|
42
34
|
def serialize(value, _strict)
|
43
35
|
value
|
44
36
|
end
|
@@ -9,6 +9,7 @@ require 'avromatic/model/types/enum_type'
|
|
9
9
|
require 'avromatic/model/types/fixed_type'
|
10
10
|
require 'avromatic/model/types/float_type'
|
11
11
|
require 'avromatic/model/types/integer_type'
|
12
|
+
require 'avromatic/model/types/big_int_type'
|
12
13
|
require 'avromatic/model/types/map_type'
|
13
14
|
require 'avromatic/model/types/null_type'
|
14
15
|
require 'avromatic/model/types/record_type'
|
@@ -31,7 +32,7 @@ module Avromatic
|
|
31
32
|
'bytes' => Avromatic::Model::Types::StringType.new,
|
32
33
|
'boolean' => Avromatic::Model::Types::BooleanType.new,
|
33
34
|
'int' => Avromatic::Model::Types::IntegerType.new,
|
34
|
-
'long' => Avromatic::Model::Types::
|
35
|
+
'long' => Avromatic::Model::Types::BigIntType.new,
|
35
36
|
'float' => Avromatic::Model::Types::FloatType.new,
|
36
37
|
'double' => Avromatic::Model::Types::FloatType.new,
|
37
38
|
'null' => Avromatic::Model::Types::NullType.new
|
@@ -76,7 +76,15 @@ module Avromatic
|
|
76
76
|
private
|
77
77
|
|
78
78
|
def find_index(value)
|
79
|
-
|
79
|
+
if value.is_a?(::Integer)
|
80
|
+
if Avromatic::Model::Types::IntegerType.in_range?(value)
|
81
|
+
return member_types.index { |member_type| member_type.is_a?(Avromatic::Model::Types::IntegerType) }
|
82
|
+
elsif Avromatic::Model::Types::BigIntType.in_range?(value)
|
83
|
+
return member_types.index { |member_type| member_type.is_a?(Avromatic::Model::Types::BigIntType) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# TODO: Consider caching the index for each value class
|
80
88
|
member_types.find_index do |member_type|
|
81
89
|
member_type.value_classes.any? { |value_class| value.is_a?(value_class) }
|
82
90
|
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: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '8'
|
22
|
+
version: '8.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '8'
|
32
|
+
version: '8.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '5.2'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '8'
|
42
|
+
version: '8.1'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '5.2'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '8'
|
52
|
+
version: '8.1'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: avro
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -298,6 +298,7 @@ files:
|
|
298
298
|
- lib/avromatic/model/types/abstract_timestamp_type.rb
|
299
299
|
- lib/avromatic/model/types/abstract_type.rb
|
300
300
|
- lib/avromatic/model/types/array_type.rb
|
301
|
+
- lib/avromatic/model/types/big_int_type.rb
|
301
302
|
- lib/avromatic/model/types/boolean_type.rb
|
302
303
|
- lib/avromatic/model/types/custom_type.rb
|
303
304
|
- lib/avromatic/model/types/date_type.rb
|