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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca90775e4837946637599b38d56387f984dd670ccf40b10b4e99c5ac83f6bb51
4
- data.tar.gz: 571a777f61bc5e01529ce32b3b4fe7f38a224b36f0aff511b569beec9b68d28d
3
+ metadata.gz: 4546ee5b80f3b538d7c3f9813501f066ef1f033693f5328f8789f26f9d7537dc
4
+ data.tar.gz: 3c658049c62dcd8ab506bc3cc72fa926731fd8a712c1436f0277339edc88d290
5
5
  SHA512:
6
- metadata.gz: cc598d7b96ca9afed3c662b8cbd2473e5c49254b55249439efe3d4407088dca7f12ad683d010d05af17db95dbac7afaa8994066d54d5032db0ed1f811e6cdc41
7
- data.tar.gz: e01498f7da67da3f49114775c22b799d93630d6205ca95ff5197e11b21bb55069c67a01f007f0e7e609c7f2848ef3f783e3cdb2afd9d9a0901bb7fab63430c8a
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sorbet-schema (0.9.1)
4
+ sorbet-schema (0.9.2)
5
5
  sorbet-result (~> 1.1)
6
6
  sorbet-runtime (~> 0.5)
7
7
  sorbet-struct-comparable (~> 1.3)
@@ -1,5 +1,5 @@
1
1
  # typed: strict
2
2
 
3
3
  module SorbetSchema
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.2"
5
5
  end
@@ -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
- coercion_result = Coercion.coerce(type: field.type, value:)
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.1
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-08-14 00:00:00.000000000 Z
11
+ date: 2024-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-result