dry-types 1.8.3 → 1.9.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/CHANGELOG.md +185 -226
- data/LICENSE +1 -1
- data/README.md +7 -13
- data/dry-types.gemspec +24 -18
- data/lib/dry/types/any.rb +1 -1
- data/lib/dry/types/array/member.rb +3 -5
- data/lib/dry/types/builder.rb +18 -2
- data/lib/dry/types/coercions/params.rb +4 -4
- data/lib/dry/types/coercions.rb +8 -8
- data/lib/dry/types/compiler.rb +10 -3
- data/lib/dry/types/constructor/function.rb +6 -6
- data/lib/dry/types/constructor/wrapper.rb +2 -2
- data/lib/dry/types/constructor.rb +4 -4
- data/lib/dry/types/hash.rb +3 -3
- data/lib/dry/types/map.rb +1 -1
- data/lib/dry/types/meta.rb +7 -1
- data/lib/dry/types/nominal.rb +25 -1
- data/lib/dry/types/options.rb +5 -1
- data/lib/dry/types/params.rb +20 -49
- data/lib/dry/types/predicate_inferrer.rb +1 -1
- data/lib/dry/types/primitive_inferrer.rb +4 -16
- data/lib/dry/types/printer.rb +17 -1
- data/lib/dry/types/schema.rb +7 -7
- data/lib/dry/types/sum.rb +13 -0
- data/lib/dry/types/version.rb +1 -1
- data/lib/dry/types.rb +14 -15
- metadata +69 -13
data/lib/dry/types/sum.rb
CHANGED
|
@@ -4,6 +4,16 @@ module Dry
|
|
|
4
4
|
module Types
|
|
5
5
|
# Sum type
|
|
6
6
|
#
|
|
7
|
+
# Sum types try each constituent type from left to right and return the result
|
|
8
|
+
# from the first successful type. If all types fail, the error from the rightmost
|
|
9
|
+
# (last attempted) type is raised, not necessarily the most "relevant" error.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# # Given: FixedAmount | Percentage
|
|
13
|
+
# # Input: { type: "fixed", value: -1.1 }
|
|
14
|
+
# # FixedAmount fails on value constraint, Percentage fails on type mismatch
|
|
15
|
+
# # Error raised will be from Percentage (rightmost), not FixedAmount
|
|
16
|
+
#
|
|
7
17
|
# @api public
|
|
8
18
|
class Sum
|
|
9
19
|
include Composition
|
|
@@ -19,6 +29,9 @@ module Dry
|
|
|
19
29
|
#
|
|
20
30
|
# @return [Object]
|
|
21
31
|
#
|
|
32
|
+
# @note Tries left type first, then right type. If both fail, raises the
|
|
33
|
+
# error from the right (last attempted) type for performance reasons.
|
|
34
|
+
#
|
|
22
35
|
# @api private
|
|
23
36
|
def call_unsafe(input)
|
|
24
37
|
left.call_safe(input) { right.call_unsafe(input) }
|
data/lib/dry/types/version.rb
CHANGED
data/lib/dry/types.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require "bigdecimal"
|
|
4
4
|
require "date"
|
|
5
|
-
require "set"
|
|
6
5
|
require "zeitwerk"
|
|
7
6
|
|
|
8
7
|
require "concurrent/map"
|
|
@@ -43,17 +42,10 @@ module Dry
|
|
|
43
42
|
"#{root}/dry/types/printer",
|
|
44
43
|
"#{root}/dry/types/spec/types.rb",
|
|
45
44
|
"#{root}/dry/types/{#{%w[
|
|
46
|
-
compat
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
extensions
|
|
51
|
-
inflector
|
|
52
|
-
module
|
|
53
|
-
json
|
|
54
|
-
params
|
|
55
|
-
printer
|
|
56
|
-
version
|
|
45
|
+
compat constraints core
|
|
46
|
+
errors extensions inflector
|
|
47
|
+
module json params
|
|
48
|
+
printer version
|
|
57
49
|
].join(",")}}.rb"
|
|
58
50
|
)
|
|
59
51
|
end
|
|
@@ -61,6 +53,15 @@ module Dry
|
|
|
61
53
|
|
|
62
54
|
loader.setup
|
|
63
55
|
|
|
56
|
+
# Whether Type#optional should reach for Types["params.nil"]
|
|
57
|
+
# instead of Types["nil"] when called on a Params type.
|
|
58
|
+
# When use_namespaced_optionals is set to true
|
|
59
|
+
# Types["params.integer"].optional will be identical to
|
|
60
|
+
# Types["optional.params.integer"], that is an empty string
|
|
61
|
+
# will be treated as nil
|
|
62
|
+
defines :use_namespaced_optionals
|
|
63
|
+
use_namespaced_optionals false
|
|
64
|
+
|
|
64
65
|
# @see Dry.Types
|
|
65
66
|
def self.module(*namespaces, default: :nominal, **aliases)
|
|
66
67
|
::Module.new(container, *namespaces, default: default, **aliases)
|
|
@@ -70,9 +71,7 @@ module Dry
|
|
|
70
71
|
DEPRECATION
|
|
71
72
|
|
|
72
73
|
# @api private
|
|
73
|
-
def self.included(*)
|
|
74
|
-
raise "Import Dry.Types, not Dry::Types"
|
|
75
|
-
end
|
|
74
|
+
def self.included(*) = raise "Import Dry.Types, not Dry::Types"
|
|
76
75
|
|
|
77
76
|
# Return container with registered built-in type objects
|
|
78
77
|
#
|
metadata
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dry-types
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
8
|
-
autorequire:
|
|
7
|
+
- Hanakai team
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bigdecimal
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
18
|
version: '3.0'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '3.0'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
@@ -94,13 +93,72 @@ dependencies:
|
|
|
94
93
|
- - "~>"
|
|
95
94
|
- !ruby/object:Gem::Version
|
|
96
95
|
version: '2.6'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: bundler
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rake
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: rspec
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
type: :development
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
- !ruby/object:Gem::Dependency
|
|
139
|
+
name: yard
|
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
145
|
+
type: :development
|
|
146
|
+
prerelease: false
|
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
148
|
+
requirements:
|
|
149
|
+
- - ">="
|
|
150
|
+
- !ruby/object:Gem::Version
|
|
151
|
+
version: '0'
|
|
97
152
|
description: Type system for Ruby supporting coercions, constraints and complex types
|
|
98
153
|
like structs, value objects, enums etc
|
|
99
154
|
email:
|
|
100
|
-
-
|
|
155
|
+
- info@hanakai.org
|
|
101
156
|
executables: []
|
|
102
157
|
extensions: []
|
|
103
|
-
extra_rdoc_files:
|
|
158
|
+
extra_rdoc_files:
|
|
159
|
+
- CHANGELOG.md
|
|
160
|
+
- LICENSE
|
|
161
|
+
- README.md
|
|
104
162
|
files:
|
|
105
163
|
- CHANGELOG.md
|
|
106
164
|
- LICENSE
|
|
@@ -170,8 +228,7 @@ metadata:
|
|
|
170
228
|
changelog_uri: https://github.com/dry-rb/dry-types/blob/main/CHANGELOG.md
|
|
171
229
|
source_code_uri: https://github.com/dry-rb/dry-types
|
|
172
230
|
bug_tracker_uri: https://github.com/dry-rb/dry-types/issues
|
|
173
|
-
|
|
174
|
-
post_install_message:
|
|
231
|
+
funding_uri: https://github.com/sponsors/hanami
|
|
175
232
|
rdoc_options: []
|
|
176
233
|
require_paths:
|
|
177
234
|
- lib
|
|
@@ -179,15 +236,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
179
236
|
requirements:
|
|
180
237
|
- - ">="
|
|
181
238
|
- !ruby/object:Gem::Version
|
|
182
|
-
version: '3.
|
|
239
|
+
version: '3.2'
|
|
183
240
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
241
|
requirements:
|
|
185
242
|
- - ">="
|
|
186
243
|
- !ruby/object:Gem::Version
|
|
187
244
|
version: '0'
|
|
188
245
|
requirements: []
|
|
189
|
-
rubygems_version: 3.
|
|
190
|
-
signing_key:
|
|
246
|
+
rubygems_version: 3.6.9
|
|
191
247
|
specification_version: 4
|
|
192
248
|
summary: Type system for Ruby supporting coercions, constraints and complex types
|
|
193
249
|
like structs, value objects, enums etc
|