dry-types 1.0.1 → 1.2.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/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +34 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.travis.yml +10 -4
- data/CHANGELOG.md +101 -3
- data/Gemfile +9 -6
- data/README.md +2 -2
- data/Rakefile +2 -2
- data/benchmarks/hash_schemas.rb +8 -6
- data/benchmarks/lax_schema.rb +0 -1
- data/benchmarks/profile_invalid_input.rb +1 -1
- data/benchmarks/profile_lax_schema_valid.rb +1 -1
- data/benchmarks/profile_valid_input.rb +1 -1
- data/docsite/source/array-with-member.html.md +13 -0
- data/docsite/source/built-in-types.html.md +116 -0
- data/docsite/source/constraints.html.md +31 -0
- data/docsite/source/custom-types.html.md +93 -0
- data/docsite/source/default-values.html.md +91 -0
- data/docsite/source/enum.html.md +69 -0
- data/docsite/source/getting-started.html.md +57 -0
- data/docsite/source/hash-schemas.html.md +169 -0
- data/docsite/source/index.html.md +155 -0
- data/docsite/source/map.html.md +17 -0
- data/docsite/source/optional-values.html.md +96 -0
- data/docsite/source/sum.html.md +21 -0
- data/dry-types.gemspec +19 -19
- data/lib/dry/types.rb +9 -4
- data/lib/dry/types/array.rb +6 -0
- data/lib/dry/types/array/constructor.rb +32 -0
- data/lib/dry/types/array/member.rb +8 -1
- data/lib/dry/types/builder.rb +1 -1
- data/lib/dry/types/builder_methods.rb +33 -23
- data/lib/dry/types/coercions.rb +19 -6
- data/lib/dry/types/coercions/params.rb +4 -4
- data/lib/dry/types/constrained.rb +5 -0
- data/lib/dry/types/constructor.rb +5 -37
- data/lib/dry/types/constructor/function.rb +4 -5
- data/lib/dry/types/core.rb +27 -8
- data/lib/dry/types/decorator.rb +1 -1
- data/lib/dry/types/enum.rb +1 -0
- data/lib/dry/types/extensions.rb +4 -0
- data/lib/dry/types/extensions/maybe.rb +9 -1
- data/lib/dry/types/extensions/monads.rb +29 -0
- data/lib/dry/types/hash.rb +10 -11
- data/lib/dry/types/hash/constructor.rb +5 -5
- data/lib/dry/types/json.rb +4 -0
- data/lib/dry/types/lax.rb +4 -4
- data/lib/dry/types/map.rb +8 -4
- data/lib/dry/types/module.rb +3 -3
- data/lib/dry/types/nominal.rb +3 -4
- data/lib/dry/types/params.rb +9 -0
- data/lib/dry/types/predicate_inferrer.rb +197 -0
- data/lib/dry/types/predicate_registry.rb +34 -0
- data/lib/dry/types/primitive_inferrer.rb +97 -0
- data/lib/dry/types/printer.rb +17 -12
- data/lib/dry/types/schema.rb +14 -20
- data/lib/dry/types/schema/key.rb +19 -1
- data/lib/dry/types/spec/types.rb +3 -6
- data/lib/dry/types/version.rb +1 -1
- metadata +79 -52
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87e78ecf331ef9c4d95759bf28c2694e413df18fd0397d3c3c51380320328417
|
|
4
|
+
data.tar.gz: ca84bf0a23d37d7f0beda024d573852d2a0701a76f54dee2255166981bd716c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ae0d71644bfc391ada28229a68010a378b07e252c6ea5fdc27327065cdfc980b27a25bd9d63068966803a800a262958ef4ea0fc0296d4e865534e3fb3458dc8
|
|
7
|
+
data.tar.gz: a1e899fb498a414f3920f9a19bc8ca22fc4db2bf7e6063a7baca389c528c0fb4d9114522d57606d7143c872b6847b9f1134f04326d1dc5ba694853a0c3977390
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "\U0001F41B Bug report"
|
|
3
|
+
about: See CONTRIBUTING.md for more information
|
|
4
|
+
title: ''
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
|
|
11
|
+
|
|
12
|
+
For more information see [our contribution guidelines](https://github.com/rom-rb/rom/blob/master/CONTRIBUTING.md)
|
|
13
|
+
|
|
14
|
+
**Before you report**
|
|
15
|
+
|
|
16
|
+
:warning: If you have a problem related to a schema, please **report it under [dry-schema issues](https://github.com/dry-rb/dry-schema/issues/new?assignees=&labels=bug&template=---bug-report.md&title=)** instead.
|
|
17
|
+
|
|
18
|
+
**Describe the bug**
|
|
19
|
+
|
|
20
|
+
A clear and concise description of what the bug is.
|
|
21
|
+
|
|
22
|
+
**To Reproduce**
|
|
23
|
+
|
|
24
|
+
Provide detailed steps to reproduce, an executable script would be best.
|
|
25
|
+
|
|
26
|
+
**Expected behavior**
|
|
27
|
+
|
|
28
|
+
A clear and concise description of what you expected to happen.
|
|
29
|
+
|
|
30
|
+
**Your environment**
|
|
31
|
+
|
|
32
|
+
- Affects my production application: **YES/NO**
|
|
33
|
+
- Ruby version: ...
|
|
34
|
+
- OS: ...
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "\U0001F6E0 Feature request"
|
|
3
|
+
about: See CONTRIBUTING.md for more information
|
|
4
|
+
title: ''
|
|
5
|
+
labels: feature
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Summary of what the feature is supposed to do.
|
|
11
|
+
|
|
12
|
+
## Examples
|
|
13
|
+
|
|
14
|
+
Code examples showing how the feature could be used.
|
|
15
|
+
|
|
16
|
+
## Resources
|
|
17
|
+
|
|
18
|
+
Additional information, like a link to the discussion forum thread where the feature was discussed etc.
|
data/.travis.yml
CHANGED
|
@@ -10,13 +10,19 @@ after_script:
|
|
|
10
10
|
script:
|
|
11
11
|
- bundle exec rake
|
|
12
12
|
rvm:
|
|
13
|
-
- 2.6.
|
|
14
|
-
- 2.5.
|
|
15
|
-
- 2.4.
|
|
16
|
-
-
|
|
13
|
+
- 2.6.5
|
|
14
|
+
- 2.5.7
|
|
15
|
+
- 2.4.9
|
|
16
|
+
- ruby-head
|
|
17
17
|
env:
|
|
18
18
|
global:
|
|
19
19
|
- COVERAGE=true
|
|
20
|
+
matrix:
|
|
21
|
+
allow_failures:
|
|
22
|
+
- rvm: ruby-head
|
|
23
|
+
include:
|
|
24
|
+
- rvm: jruby-9.2.8.0
|
|
25
|
+
jdk: openjdk8
|
|
20
26
|
notifications:
|
|
21
27
|
email: false
|
|
22
28
|
webhooks:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,98 @@
|
|
|
1
|
+
# 1.2.0 2019-10-06
|
|
2
|
+
|
|
3
|
+
## Changed
|
|
4
|
+
|
|
5
|
+
- `Dry::Types.[]` used to work with classes, now it's deprecated (flash-gordon)
|
|
6
|
+
|
|
7
|
+
## Fixed
|
|
8
|
+
|
|
9
|
+
- Bug with using a `Bool`-named struct as a schema key (flash-gordon)
|
|
10
|
+
- A bunch of issues related to using `meta` on complex types (flash-gordon)
|
|
11
|
+
- `Types.Constructor(...)` returns a `Types::Array` as it should (flash-gordon)
|
|
12
|
+
|
|
13
|
+
## Added
|
|
14
|
+
|
|
15
|
+
- `Optional::Params` types that coerce empty strings to `nil` (flash-gordon)
|
|
16
|
+
```ruby
|
|
17
|
+
Dry::Types['optional.params.integer'].('') # => nil
|
|
18
|
+
Dry::Types['optional.params.integer'].('140') # => 140
|
|
19
|
+
Dry::Types['optional.params.integer'].('asd') # => exception!
|
|
20
|
+
```
|
|
21
|
+
Keep in mind, Dry::Types['optional.params.integer'] and Dry::Types['params.integer'].optional are not the same, the latter doesn't handle empty strings.
|
|
22
|
+
- Predicate inferrer was ported from dry-schema (authored by solnic)
|
|
23
|
+
```ruby
|
|
24
|
+
require 'dry/types/predicate_inferrer'
|
|
25
|
+
Dry::Types::PredicateInferrer.new[Types::String]
|
|
26
|
+
# => [:str?]
|
|
27
|
+
Dry::Types::PredicateInferrer.new[Types::String | Types::Integer]
|
|
28
|
+
# => [[[:str?], [:int?]]]
|
|
29
|
+
```
|
|
30
|
+
Note that the API of the predicate inferrer can change in the stable version, it's dictated by the needs of dry-schema so it should be considered as semi-stable. If you depend on it, write specs covering the desired behavior. Another option is copy-and-paste the whole thing to your project.
|
|
31
|
+
- Primitive inferrer was ported from dry-schema (authored by solnic)
|
|
32
|
+
```ruby
|
|
33
|
+
require 'dry/types/primitive_inferrer'
|
|
34
|
+
Dry::Types::PrimitiveInferrer.new[Types::String]
|
|
35
|
+
# => [String]
|
|
36
|
+
Dry::Types::PrimitiveInferrer.new[Types::String | Types::Integer]
|
|
37
|
+
# => [String, Integer]
|
|
38
|
+
Dry::Types::PrimitiveInferrer.new[Types::String.optional]
|
|
39
|
+
# => [NilClass, String]
|
|
40
|
+
```
|
|
41
|
+
The primitive inferrer should be stable by now, you can rely on it.
|
|
42
|
+
- The `monads` extension adds `Dry::Types::Result#to_monad`. This makes it compatible with do notation from dry-monads. Load it with `Dry::Types.load_extensions(:monads)` (skryukov)
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
Types = Dry.Types
|
|
46
|
+
Dry::Types.load_extensions(:monads)
|
|
47
|
+
|
|
48
|
+
class AddTen
|
|
49
|
+
include Dry::Monads[:result, :do]
|
|
50
|
+
|
|
51
|
+
def call(input)
|
|
52
|
+
integer = yield Types::Coercible::Integer.try(input)
|
|
53
|
+
|
|
54
|
+
Success(integer + 10)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
[Compare v1.1.1...v1.2.0](https://github.com/dry-rb/dry-types/compare/v1.1.1...v1.2.0)
|
|
60
|
+
|
|
61
|
+
# 1.1.1 2019-07-26
|
|
62
|
+
|
|
63
|
+
## Fixed
|
|
64
|
+
|
|
65
|
+
- A bug where meta was lost for lax array types (flash-gordon)
|
|
66
|
+
|
|
67
|
+
[Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-types/compare/v1.1.0...v1.1.1)
|
|
68
|
+
|
|
69
|
+
# 1.1.0 2019-07-02
|
|
70
|
+
|
|
71
|
+
## Added
|
|
72
|
+
|
|
73
|
+
- New builder method `Interface` constructs a type which accepts objects that respond to the given methods (waiting-for-dev)
|
|
74
|
+
```ruby
|
|
75
|
+
Types = Dry.Types()
|
|
76
|
+
Types::Callable = Types.Interface(:call)
|
|
77
|
+
Types::Callable.valid?(Object.new) # => false
|
|
78
|
+
Types::Callable.valid?(proc {}) # => true
|
|
79
|
+
```
|
|
80
|
+
- New types: `coercible.symbol`, `params.symbol`, and `json.symbol`, all use `.to_sym` for coercion (waiting-for-dev)
|
|
81
|
+
|
|
82
|
+
## Fixed
|
|
83
|
+
|
|
84
|
+
- Converting schema keys to maybe types (flash-gordon)
|
|
85
|
+
- Using `Schema#key` and `Array#member` on constuctors (flash-gordon)
|
|
86
|
+
- Using `meta(omittable: true)` within `transform_types` works again but produces a warning, please migrate to `.omittable` or `.required(false)` (flash-gordon)
|
|
87
|
+
- Bug with a constructror defined on top of enum (flash-gordon)
|
|
88
|
+
|
|
89
|
+
[Compare v1.0.1...v1.1.0](https://github.com/dry-rb/dry-types/compare/v1.0.1...v1.1.0)
|
|
90
|
+
|
|
1
91
|
# 1.0.1 2019-06-04
|
|
2
92
|
|
|
3
93
|
## Added
|
|
4
94
|
|
|
5
|
-
- In
|
|
95
|
+
- In a case of failure the constructor block can now pass a different value (flash-gordon)
|
|
6
96
|
```ruby
|
|
7
97
|
not_empty_string = Types::String.constructor do |value, &failure|
|
|
8
98
|
value.strip.empty? ? failure.(nil) : value.strip
|
|
@@ -21,6 +111,7 @@
|
|
|
21
111
|
|
|
22
112
|
- [BREAKING] Behavior of built-in constructor types was changed to be more strict. They will always raise an error on failed coercion (flash-gordon)
|
|
23
113
|
Compare:
|
|
114
|
+
|
|
24
115
|
```ruby
|
|
25
116
|
# 0.15.0
|
|
26
117
|
Types::Params::Integer.('foo')
|
|
@@ -36,7 +127,9 @@
|
|
|
36
127
|
```ruby
|
|
37
128
|
Types::Params::Integer.('foo') { :invalid } # => :invalid
|
|
38
129
|
```
|
|
130
|
+
|
|
39
131
|
This makes work with coercions more straightforward and way faster.
|
|
132
|
+
|
|
40
133
|
- [BREAKING] Safe types were renamed to Lax, this name better serves their purpose. The previous name is available but prints a warning (flash-gordon)
|
|
41
134
|
- [BREAKING] Metadata is now pushed down to the decorated type. It is not likely you will notice a difference but this a breaking change that enables some use cases in rom related to the usage of default types in relations (flash-gordon)
|
|
42
135
|
- Nominal types are now completely unconstrained. This fixes some inconsistencies when using them with constraints. `Nominal#try` will always return a successful result, for the previous behavior use `Nominal#try_coerce` or switch to strict types with passing a block to `#call` (flash-gordon)
|
|
@@ -159,6 +252,7 @@
|
|
|
159
252
|
)
|
|
160
253
|
```
|
|
161
254
|
- Key types have API for making keys omittable and back (flash-gordon)
|
|
255
|
+
|
|
162
256
|
```ruby
|
|
163
257
|
# defining a base schema with optional keys
|
|
164
258
|
lax_hash = Dry::Types['hash'].with_type_transform { |key| key.required(false) }
|
|
@@ -168,8 +262,10 @@
|
|
|
168
262
|
# keys in user_schema are not required
|
|
169
263
|
user_schema = lax_hash.schema(name: 'string', age: 'integer')
|
|
170
264
|
```
|
|
265
|
+
|
|
171
266
|
- `Type#optional?` now recognizes more cases where `nil` is an allowed value (flash-gordon)
|
|
172
267
|
- `Constructor#{prepend,append}` with `<<` and `>>` as aliases. `Constructor#append` works the same way `Constructor#constrcutor` does. `Constuctor#prepend` chains functions in the reverse order, see examples (flash-gordon)
|
|
268
|
+
|
|
173
269
|
```ruby
|
|
174
270
|
to_int = Types::Coercible::Integer
|
|
175
271
|
inc = to_int.append { |x| x + 2 }
|
|
@@ -178,6 +274,7 @@
|
|
|
178
274
|
inc = to_int.prepend { |x| x + "2" }
|
|
179
275
|
inc.("1") # => "1" -> "12" -> 12
|
|
180
276
|
```
|
|
277
|
+
|
|
181
278
|
- Partial schema application for cases when you want to validate only a subset of keys (flash-gordon)
|
|
182
279
|
This is useful when you want to update a key or two in an already-validated hash. A perfect example is `Dry::Struct#new` where this feature is now used.
|
|
183
280
|
```ruby
|
|
@@ -189,14 +286,15 @@
|
|
|
189
286
|
|
|
190
287
|
## Fixed
|
|
191
288
|
|
|
192
|
-
|
|
193
|
-
|
|
289
|
+
- `Hash::Map` now behaves as a constrained type if its values are constrained (flash-gordon)
|
|
290
|
+
- `coercible.integer` now doesn't blow up on invalid strings (exterm)
|
|
194
291
|
|
|
195
292
|
[Compare v0.14.0...v0.15.0](https://github.com/dry-rb/dry-types/compare/v0.14.0...v0.15.0)
|
|
196
293
|
|
|
197
294
|
# v0.14.1 2019-03-25
|
|
198
295
|
|
|
199
296
|
## Fixed
|
|
297
|
+
|
|
200
298
|
- `coercible.integer` now doesn't blow up on invalid strings (exterm)
|
|
201
299
|
|
|
202
300
|
[Compare v0.14.0...v0.14.1](https://github.com/dry-rb/dry-types/compare/v0.14.0...v0.14.1)
|
data/Gemfile
CHANGED
|
@@ -14,13 +14,16 @@ end
|
|
|
14
14
|
|
|
15
15
|
group :tools do
|
|
16
16
|
gem 'pry-byebug', platform: :mri
|
|
17
|
+
gem 'rubocop'
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
group :benchmarks do
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
platform :mri do
|
|
22
|
+
gem 'attrio'
|
|
23
|
+
gem 'benchmark-ips'
|
|
24
|
+
gem 'dry-struct'
|
|
25
|
+
gem 'fast_attributes'
|
|
26
|
+
gem 'hotch'
|
|
27
|
+
gem 'virtus'
|
|
28
|
+
end
|
|
26
29
|
end
|
data/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[gem]: https://rubygems.org/gems/dry-types
|
|
2
|
-
[travis]: https://travis-ci.
|
|
2
|
+
[travis]: https://travis-ci.com/dry-rb/dry-types
|
|
3
3
|
[codeclimate]: https://codeclimate.com/github/dry-rb/dry-types
|
|
4
4
|
[coveralls]: https://coveralls.io/r/dry-rb/dry-types
|
|
5
5
|
[inchpages]: http://inch-ci.org/github/dry-rb/dry-types
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
# dry-types [][chat]
|
|
9
9
|
|
|
10
10
|
[][gem]
|
|
11
|
-
[][travis]
|
|
12
12
|
[][codeclimate]
|
|
13
13
|
[][codeclimate]
|
|
14
14
|
[][inchpages]
|
data/Rakefile
CHANGED
data/benchmarks/hash_schemas.rb
CHANGED
|
@@ -7,11 +7,13 @@ require 'dry-types'
|
|
|
7
7
|
|
|
8
8
|
module SchemaBench
|
|
9
9
|
def self.hash_schema(type)
|
|
10
|
-
Dry::Types['nominal.hash'].public_send(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
Dry::Types['nominal.hash'].public_send(
|
|
11
|
+
type,
|
|
12
|
+
email: Dry::Types['nominal.string'],
|
|
13
|
+
age: Dry::Types['params.integer'],
|
|
14
|
+
admin: Dry::Types['params.bool'],
|
|
15
|
+
address: Dry::Types['nominal.hash'].public_send(
|
|
16
|
+
type,
|
|
15
17
|
city: Dry::Types['nominal.string'],
|
|
16
18
|
street: Dry::Types['nominal.string']
|
|
17
19
|
)
|
|
@@ -31,7 +33,7 @@ module SchemaBench
|
|
|
31
33
|
age: '20',
|
|
32
34
|
admin: '1',
|
|
33
35
|
address: { city: 'NYC', street: 'Street 1/2' }
|
|
34
|
-
}
|
|
36
|
+
}.freeze
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
require 'benchmark/ips'
|
data/benchmarks/lax_schema.rb
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Array With Member
|
|
3
|
+
layout: gem-single
|
|
4
|
+
name: dry-types
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The built-in array type supports defining the member's type:
|
|
8
|
+
|
|
9
|
+
``` ruby
|
|
10
|
+
PostStatuses = Types::Array.of(Types::Coercible::String)
|
|
11
|
+
|
|
12
|
+
PostStatuses[[:foo, :bar]] # ["foo", "bar"]
|
|
13
|
+
```
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Built-in Types
|
|
3
|
+
layout: gem-single
|
|
4
|
+
name: dry-types
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Built-in types are grouped under 6 categories:
|
|
8
|
+
|
|
9
|
+
- `nominal` - base type definitions with a primitive class and options
|
|
10
|
+
- `strict` - constrained types with a primitive type check applied to input
|
|
11
|
+
- `coercible` - types with constructors using kernel coercions
|
|
12
|
+
- `params` - types with constructors performing non-strict coercions specific to HTTP parameters
|
|
13
|
+
- `json` - types with constructors performing non-strict coercions specific to JSON
|
|
14
|
+
- `maybe` - types accepting either nil or a specific primitive type
|
|
15
|
+
|
|
16
|
+
### Categories
|
|
17
|
+
|
|
18
|
+
Assuming you included `Dry::Types` ([see instructions](/gems/dry-types/1.0/getting-started)) in a module called `Types`:
|
|
19
|
+
|
|
20
|
+
* Nominal types:
|
|
21
|
+
- `Types::Nominal::Any`
|
|
22
|
+
- `Types::Nominal::Nil`
|
|
23
|
+
- `Types::Nominal::Symbol`
|
|
24
|
+
- `Types::Nominal::Class`
|
|
25
|
+
- `Types::Nominal::True`
|
|
26
|
+
- `Types::Nominal::False`
|
|
27
|
+
- `Types::Nominal::Bool`
|
|
28
|
+
- `Types::Nominal::Integer`
|
|
29
|
+
- `Types::Nominal::Float`
|
|
30
|
+
- `Types::Nominal::Decimal`
|
|
31
|
+
- `Types::Nominal::String`
|
|
32
|
+
- `Types::Nominal::Date`
|
|
33
|
+
- `Types::Nominal::DateTime`
|
|
34
|
+
- `Types::Nominal::Time`
|
|
35
|
+
- `Types::Nominal::Array`
|
|
36
|
+
- `Types::Nominal::Hash`
|
|
37
|
+
|
|
38
|
+
* `Strict` types will raise an error if passed a value of the wrong type:
|
|
39
|
+
- `Types::Strict::Nil`
|
|
40
|
+
- `Types::Strict::Symbol`
|
|
41
|
+
- `Types::Strict::Class`
|
|
42
|
+
- `Types::Strict::True`
|
|
43
|
+
- `Types::Strict::False`
|
|
44
|
+
- `Types::Strict::Bool`
|
|
45
|
+
- `Types::Strict::Integer`
|
|
46
|
+
- `Types::Strict::Float`
|
|
47
|
+
- `Types::Strict::Decimal`
|
|
48
|
+
- `Types::Strict::String`
|
|
49
|
+
- `Types::Strict::Date`
|
|
50
|
+
- `Types::Strict::DateTime`
|
|
51
|
+
- `Types::Strict::Time`
|
|
52
|
+
- `Types::Strict::Array`
|
|
53
|
+
- `Types::Strict::Hash`
|
|
54
|
+
|
|
55
|
+
> All types in the `strict` category are [constrained](/gems/dry-types/1.0/constraints) by a type-check that is applied to make sure that the input is an instance of the primitive:
|
|
56
|
+
|
|
57
|
+
``` ruby
|
|
58
|
+
Types::Strict::Integer[1] # => 1
|
|
59
|
+
Types::Strict::Integer['1'] # => raises Dry::Types::ConstraintError
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
* `Coercible` types will attempt to cast values to the correct class using kernel coercion methods:
|
|
63
|
+
- `Types::Coercible::String`
|
|
64
|
+
- `Types::Coercible::Integer`
|
|
65
|
+
- `Types::Coercible::Float`
|
|
66
|
+
- `Types::Coercible::Decimal`
|
|
67
|
+
- `Types::Coercible::Array`
|
|
68
|
+
- `Types::Coercible::Hash`
|
|
69
|
+
|
|
70
|
+
* Types suitable for `Params` param processing with coercions:
|
|
71
|
+
- `Types::Params::Nil`
|
|
72
|
+
- `Types::Params::Date`
|
|
73
|
+
- `Types::Params::DateTime`
|
|
74
|
+
- `Types::Params::Time`
|
|
75
|
+
- `Types::Params::True`
|
|
76
|
+
- `Types::Params::False`
|
|
77
|
+
- `Types::Params::Bool`
|
|
78
|
+
- `Types::Params::Integer`
|
|
79
|
+
- `Types::Params::Float`
|
|
80
|
+
- `Types::Params::Decimal`
|
|
81
|
+
- `Types::Params::Array`
|
|
82
|
+
- `Types::Params::Hash`
|
|
83
|
+
|
|
84
|
+
* Types suitable for `JSON` processing with coercions:
|
|
85
|
+
- `Types::JSON::Nil`
|
|
86
|
+
- `Types::JSON::Date`
|
|
87
|
+
- `Types::JSON::DateTime`
|
|
88
|
+
- `Types::JSON::Time`
|
|
89
|
+
- `Types::JSON::Decimal`
|
|
90
|
+
- `Types::JSON::Array`
|
|
91
|
+
- `Types::JSON::Hash`
|
|
92
|
+
|
|
93
|
+
* `Maybe` strict types:
|
|
94
|
+
- `Types::Maybe::Strict::Class`
|
|
95
|
+
- `Types::Maybe::Strict::String`
|
|
96
|
+
- `Types::Maybe::Strict::Symbol`
|
|
97
|
+
- `Types::Maybe::Strict::True`
|
|
98
|
+
- `Types::Maybe::Strict::False`
|
|
99
|
+
- `Types::Maybe::Strict::Integer`
|
|
100
|
+
- `Types::Maybe::Strict::Float`
|
|
101
|
+
- `Types::Maybe::Strict::Decimal`
|
|
102
|
+
- `Types::Maybe::Strict::Date`
|
|
103
|
+
- `Types::Maybe::Strict::DateTime`
|
|
104
|
+
- `Types::Maybe::Strict::Time`
|
|
105
|
+
- `Types::Maybe::Strict::Array`
|
|
106
|
+
- `Types::Maybe::Strict::Hash`
|
|
107
|
+
|
|
108
|
+
* `Maybe` coercible types:
|
|
109
|
+
- `Types::Maybe::Coercible::String`
|
|
110
|
+
- `Types::Maybe::Coercible::Integer`
|
|
111
|
+
- `Types::Maybe::Coercible::Float`
|
|
112
|
+
- `Types::Maybe::Coercible::Decimal`
|
|
113
|
+
- `Types::Maybe::Coercible::Array`
|
|
114
|
+
- `Types::Maybe::Coercible::Hash`
|
|
115
|
+
|
|
116
|
+
> `Maybe` types are not available by default - they must be loaded using `Dry::Types.load_extensions(:maybe)`. See [Optional Values](/gems/dry-types/1.0/optional-values) for more information.
|