avromatic 0.31.0 → 0.32.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0017af435f0fc21a76680f24432fc7068f27a9a048b24e748784153c179efccd
|
4
|
+
data.tar.gz: 29095ba588695b75be4faabbd7c0e51e42f0738fb8d5224f33802f451f072f8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 375f90d488350a0a74b07a20ccb6c42cd8f613a2390d7d889702e37ce4a830f1972244cc69d1de6b29b77d29a387e4af55ebeb6a993648bd5daa63dde3a92048
|
7
|
+
data.tar.gz: 4de0b09cb599d89362fbda7f26f0cc3d3cc01ea5ffd0b2faa71b4d4c4f17476fac31d5beb120a21513c6ebc2f087d82aa639c0289fcd18cd45fcc1194d0208be
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
# avromatic changelog
|
2
2
|
|
3
|
+
## v0.32.0 (unreleased)
|
4
|
+
- Improve partial assignment using a hash for records outside of unions.
|
5
|
+
- Prevent invalid types from being assigned to primitives in unions.
|
6
|
+
- Add validation that primitive attributes have the expected type.
|
7
|
+
|
3
8
|
## v0.31.0
|
4
|
-
|
9
|
+
- Add support for Rails 5.2.
|
5
10
|
|
6
11
|
## v0.30.0
|
7
12
|
- Add `Avromatic::Model::MessageDecoder#model` method to return the Avromatic
|
@@ -12,10 +12,9 @@ module Avromatic
|
|
12
12
|
primitive Avromatic::Model::Attributes
|
13
13
|
|
14
14
|
def coerce(value)
|
15
|
-
return value if value.nil? ||
|
15
|
+
return value if value.nil? || value.is_a?(primitive)
|
16
16
|
|
17
|
-
|
18
|
-
coerced if coerced.valid?
|
17
|
+
primitive.new(value)
|
19
18
|
end
|
20
19
|
|
21
20
|
def value_coerced?(value)
|
@@ -47,7 +47,12 @@ module Avromatic
|
|
47
47
|
|
48
48
|
def safe_coerce(member_attribute, input)
|
49
49
|
coerced = member_attribute.coerce(input)
|
50
|
-
|
50
|
+
|
51
|
+
if coerced.is_a?(Avromatic::Model::Attributes)
|
52
|
+
coerced if coerced.valid?
|
53
|
+
elsif member_attribute.coerced?(coerced)
|
54
|
+
coerced
|
55
|
+
end
|
51
56
|
rescue
|
52
57
|
nil
|
53
58
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'active_support/core_ext/object/duplicable'
|
2
|
+
require 'active_support/time'
|
2
3
|
require 'ice_nine/core_ext/object'
|
4
|
+
require 'avromatic/model/allowed_type_validator'
|
3
5
|
|
4
6
|
module Avromatic
|
5
7
|
module Model
|
@@ -83,12 +85,12 @@ module Avromatic
|
|
83
85
|
field_class,
|
84
86
|
avro_field_options(field, field_class))
|
85
87
|
|
86
|
-
add_validation(field)
|
88
|
+
add_validation(field, field_class)
|
87
89
|
add_serializer(field, field_class)
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
91
|
-
def add_validation(field)
|
93
|
+
def add_validation(field, field_class)
|
92
94
|
case field.type.type_sym
|
93
95
|
when :enum
|
94
96
|
validates(field.name,
|
@@ -97,11 +99,25 @@ module Avromatic
|
|
97
99
|
validates(field.name, length: { is: field.type.size })
|
98
100
|
when :record, :array, :map, :union
|
99
101
|
validate_complex(field.name)
|
102
|
+
else
|
103
|
+
add_type_validation(field.name, field_class)
|
100
104
|
end
|
101
105
|
|
102
106
|
add_required_validation(field)
|
103
107
|
end
|
104
108
|
|
109
|
+
def add_type_validation(name, field_class)
|
110
|
+
allowed_types = if field_class == Axiom::Types::Boolean
|
111
|
+
[TrueClass, FalseClass]
|
112
|
+
elsif field_class < Avromatic::Model::Attribute::AbstractTimestamp
|
113
|
+
[Time]
|
114
|
+
else
|
115
|
+
[field_class]
|
116
|
+
end
|
117
|
+
|
118
|
+
validates(name, allowed_type: allowed_types, allow_blank: true)
|
119
|
+
end
|
120
|
+
|
105
121
|
def add_required_validation(field)
|
106
122
|
if required?(field) && field.default == :no_default
|
107
123
|
case field.type.type_sym
|
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.32.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: 2018-06-
|
11
|
+
date: 2018-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|
@@ -283,6 +283,7 @@ files:
|
|
283
283
|
- lib/avromatic/io/datum_writer.rb
|
284
284
|
- lib/avromatic/messaging.rb
|
285
285
|
- lib/avromatic/model.rb
|
286
|
+
- lib/avromatic/model/allowed_type_validator.rb
|
286
287
|
- lib/avromatic/model/allowed_writer_methods_memoization.rb
|
287
288
|
- lib/avromatic/model/attribute/abstract_timestamp.rb
|
288
289
|
- lib/avromatic/model/attribute/record.rb
|
@@ -327,9 +328,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
327
328
|
version: '0'
|
328
329
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
329
330
|
requirements:
|
330
|
-
- - "
|
331
|
+
- - ">"
|
331
332
|
- !ruby/object:Gem::Version
|
332
|
-
version:
|
333
|
+
version: 1.3.1
|
333
334
|
requirements: []
|
334
335
|
rubyforge_project:
|
335
336
|
rubygems_version: 2.7.6
|