sorbet-schema 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/sorbet-schema/version.rb +1 -1
- data/lib/typed/serializer.rb +9 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4546ee5b80f3b538d7c3f9813501f066ef1f033693f5328f8789f26f9d7537dc
|
4
|
+
data.tar.gz: 3c658049c62dcd8ab506bc3cc72fa926731fd8a712c1436f0277339edc88d290
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2f8a6bec49a48abd11c0d6ee1eac7eb9d2a85965a02633635b9361d82bad46bedb6c02d213cf226f6cb644e803c575ded85e3eaf6c06cbe9ae34068e7dd1985
|
7
|
+
data.tar.gz: db1a6c0bf48b2fd6628b77dd324e06b42d9cb7e8e222b54523e0beeb7e10395b5a86d2a3fd7b3afe36453f2b8386f3bde758cbd9893aefee9e8d1fca8490f533
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.9.2](https://github.com/maxveldink/sorbet-schema/compare/v0.9.1...v0.9.2) (2024-09-04)
|
8
|
+
|
9
|
+
|
10
|
+
### Bug Fixes
|
11
|
+
|
12
|
+
* bug coercing boolean strings ([#126](https://github.com/maxveldink/sorbet-schema/issues/126)) ([8035695](https://github.com/maxveldink/sorbet-schema/commit/8035695ab79af2b9eb03d7f6418409bd3a899084))
|
13
|
+
|
7
14
|
## [0.9.1](https://github.com/maxveldink/sorbet-schema/compare/v0.9.0...v0.9.1) (2024-08-14)
|
8
15
|
|
9
16
|
|
data/Gemfile.lock
CHANGED
data/lib/typed/serializer.rb
CHANGED
@@ -34,11 +34,19 @@ module Typed
|
|
34
34
|
def deserialize_from_creation_params(creation_params)
|
35
35
|
results = schema.fields.map do |field|
|
36
36
|
value = creation_params.fetch(field.name, nil)
|
37
|
+
coercer = Coercion::CoercerRegistry.instance.select_coercer_by(type: field.type)
|
37
38
|
|
38
39
|
if value.nil? && !field.default.nil?
|
39
40
|
Success.new(Validations::ValidatedValue.new(name: field.name, value: field.default))
|
40
41
|
elsif value.nil? || field.works_with?(value)
|
41
42
|
field.validate(value)
|
43
|
+
elsif !coercer.nil?
|
44
|
+
result = coercer.new.coerce(type: field.type, value:)
|
45
|
+
if result.success?
|
46
|
+
field.validate(result.payload)
|
47
|
+
else
|
48
|
+
Failure.new(Validations::ValidationError.new(result.error.message))
|
49
|
+
end
|
42
50
|
elsif field.type.class <= T::Types::Union
|
43
51
|
errors = []
|
44
52
|
validated_value = T.let(nil, T.nilable(Typed::Result[Typed::Validations::ValidatedValue, Typed::Validations::ValidationError]))
|
@@ -60,13 +68,7 @@ module Typed
|
|
60
68
|
|
61
69
|
validated_value.nil? ? Failure.new(Validations::ValidationError.new(errors.map(&:message).join(", "))) : validated_value
|
62
70
|
else
|
63
|
-
|
64
|
-
|
65
|
-
if coercion_result.success?
|
66
|
-
field.validate(coercion_result.payload)
|
67
|
-
else
|
68
|
-
Failure.new(Validations::ValidationError.new(coercion_result.error.message))
|
69
|
-
end
|
71
|
+
Failure.new(Validations::ValidationError.new("Coercer not found for type #{field.type}."))
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorbet-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max VelDink
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-result
|