sorbet-schema 0.7.1 → 0.7.2
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/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/sorbet-schema/version.rb +1 -1
- data/lib/typed/coercion/coercer_registry.rb +1 -0
- data/lib/typed/coercion/date_time_coercer.rb +29 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90b806c8a8d85102efd76868966f5d7ade60e2839871171bf081f8fb87483410
|
|
4
|
+
data.tar.gz: d72faf1ab20dd344c30cbf44f01f9dff090c88c97ed6f53dd945042a5de450eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ffe227e1a7c2d964001c4ab1e7510f5efc43e6b17f3108a3706eba384e67f20af4a8042ded06e6130999c87f57dd73270c55fe409f61d2d6dee067638ffbfc2b
|
|
7
|
+
data.tar.gz: 5fa47438c966fb08bb1987b3deb54bb3c8010f740c50e062df2c7d1827721d6f6a7c4283817ec21ec0dc618df4b20dc43f48f9344c18ce87fc79ad8ce0250e12
|
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.7.2](https://github.com/maxveldink/sorbet-schema/compare/v0.7.1...v0.7.2) (2024-07-11)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* add coercion support for DateTime ([#116](https://github.com/maxveldink/sorbet-schema/issues/116)) ([6f6c3e1](https://github.com/maxveldink/sorbet-schema/commit/6f6c3e151320455bc9734ebb207f746f2c139393))
|
|
13
|
+
|
|
7
14
|
## [0.7.1](https://github.com/maxveldink/sorbet-schema/compare/v0.7.0...v0.7.1) (2024-07-09)
|
|
8
15
|
|
|
9
16
|
|
data/Gemfile.lock
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
|
|
3
|
+
require "date"
|
|
4
|
+
|
|
5
|
+
module Typed
|
|
6
|
+
module Coercion
|
|
7
|
+
class DateTimeCoercer < Coercer
|
|
8
|
+
extend T::Generic
|
|
9
|
+
|
|
10
|
+
Target = type_member { {fixed: DateTime} }
|
|
11
|
+
|
|
12
|
+
sig { override.params(type: T::Types::Base).returns(T::Boolean) }
|
|
13
|
+
def used_for_type?(type)
|
|
14
|
+
T::Utils.coerce(type) == T::Utils.coerce(DateTime)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
sig { override.params(type: T::Types::Base, value: Value).returns(Result[Target, CoercionError]) }
|
|
18
|
+
def coerce(type:, value:)
|
|
19
|
+
return Failure.new(CoercionError.new("Type must be a DateTime.")) unless used_for_type?(type)
|
|
20
|
+
|
|
21
|
+
return Success.new(value) if value.is_a?(DateTime)
|
|
22
|
+
|
|
23
|
+
Success.new(DateTime.parse(value))
|
|
24
|
+
rescue Date::Error, TypeError
|
|
25
|
+
Failure.new(CoercionError.new("'#{value}' cannot be coerced into DateTime."))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sorbet-schema
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Max VelDink
|
|
@@ -94,6 +94,7 @@ files:
|
|
|
94
94
|
- lib/typed/coercion/coercion_error.rb
|
|
95
95
|
- lib/typed/coercion/coercion_not_supported_error.rb
|
|
96
96
|
- lib/typed/coercion/date_coercer.rb
|
|
97
|
+
- lib/typed/coercion/date_time_coercer.rb
|
|
97
98
|
- lib/typed/coercion/enum_coercer.rb
|
|
98
99
|
- lib/typed/coercion/float_coercer.rb
|
|
99
100
|
- lib/typed/coercion/integer_coercer.rb
|