dry-types 1.0.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -5
- 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/.github/workflows/custom_ci.yml +76 -0
- data/.github/workflows/docsite.yml +34 -0
- data/.github/workflows/sync_configs.yml +34 -0
- data/.gitignore +1 -1
- data/.rspec +3 -1
- data/.rubocop.yml +89 -0
- data/CHANGELOG.md +127 -3
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +12 -6
- data/LICENSE +17 -17
- 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/extensions.html.md +15 -0
- data/docsite/source/extensions/maybe.html.md +57 -0
- data/docsite/source/extensions/monads.html.md +61 -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 +156 -0
- data/docsite/source/map.html.md +17 -0
- data/docsite/source/optional-values.html.md +35 -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/any.rb +2 -2
- data/lib/dry/types/array.rb +6 -0
- data/lib/dry/types/array/constructor.rb +32 -0
- data/lib/dry/types/array/member.rb +10 -3
- data/lib/dry/types/builder.rb +2 -2
- data/lib/dry/types/builder_methods.rb +34 -8
- data/lib/dry/types/coercions.rb +19 -6
- data/lib/dry/types/coercions/params.rb +4 -4
- data/lib/dry/types/compiler.rb +2 -2
- data/lib/dry/types/constrained.rb +6 -1
- data/lib/dry/types/constructor.rb +10 -42
- data/lib/dry/types/constructor/function.rb +4 -5
- data/lib/dry/types/core.rb +27 -8
- data/lib/dry/types/decorator.rb +3 -2
- data/lib/dry/types/enum.rb +2 -1
- 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 +11 -12
- 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/meta.rb +1 -1
- data/lib/dry/types/module.rb +6 -6
- 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 +16 -22
- data/lib/dry/types/schema/key.rb +19 -1
- data/lib/dry/types/spec/types.rb +6 -7
- data/lib/dry/types/sum.rb +2 -2
- data/lib/dry/types/version.rb +1 -1
- metadata +67 -35
- data/.travis.yml +0 -27
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
|
data/CONTRIBUTING.md
CHANGED
@@ -10,7 +10,7 @@ Report a feature request **only after discussing it first on [discourse.dry-rb.o
|
|
10
10
|
|
11
11
|
## Reporting questions, support requests, ideas, concerns etc.
|
12
12
|
|
13
|
-
**PLEASE DON'T** - use [discourse.dry-rb.org](
|
13
|
+
**PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
|
14
14
|
|
15
15
|
# Pull Request Guidelines
|
16
16
|
|
@@ -26,4 +26,4 @@ Other requirements:
|
|
26
26
|
|
27
27
|
# Asking for help
|
28
28
|
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
|
29
|
+
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org) or join [our chat](https://dry-rb.zulipchat.com).
|
data/Gemfile
CHANGED
@@ -6,6 +6,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
6
6
|
|
7
7
|
gemspec
|
8
8
|
|
9
|
+
gem 'dry-logic', github: 'dry-rb/dry-logic', branch: 'master' if ENV['DRY_LOGIC_FROM_MASTER'].eql?('true')
|
10
|
+
|
9
11
|
group :test do
|
10
12
|
platform :mri do
|
11
13
|
gem 'simplecov', require: false
|
@@ -14,13 +16,17 @@ end
|
|
14
16
|
|
15
17
|
group :tools do
|
16
18
|
gem 'pry-byebug', platform: :mri
|
19
|
+
gem 'rubocop'
|
20
|
+
gem 'ossy', github: 'solnic/ossy', branch: 'master'
|
17
21
|
end
|
18
22
|
|
19
23
|
group :benchmarks do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
platform :mri do
|
25
|
+
gem 'attrio'
|
26
|
+
gem 'benchmark-ips'
|
27
|
+
gem 'dry-struct'
|
28
|
+
gem 'fast_attributes'
|
29
|
+
gem 'hotch'
|
30
|
+
gem 'virtus'
|
31
|
+
end
|
26
32
|
end
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
3
|
+
Copyright (c) 2015-2019 dry-rb team
|
10
4
|
|
11
|
-
|
12
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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 [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
|
9
9
|
|
10
10
|
[![Gem Version](https://badge.fury.io/rb/dry-types.svg)][gem]
|
11
|
-
[![Build Status](https://travis-ci.
|
11
|
+
[![Build Status](https://travis-ci.com/dry-rb/dry-types.svg?branch=master)][travis]
|
12
12
|
[![Code Climate](https://codeclimate.com/github/dry-rb/dry-types/badges/gpa.svg)][codeclimate]
|
13
13
|
[![Test Coverage](https://codeclimate.com/github/dry-rb/dry-types/badges/coverage.svg)][codeclimate]
|
14
14
|
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-types.svg?branch=master)][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](docs::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](docs::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 [Maybe extension](docs::extensions/maybe) for more information.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
title: Constraints
|
3
|
+
layout: gem-single
|
4
|
+
name: dry-types
|
5
|
+
---
|
6
|
+
|
7
|
+
You can create constrained types that will use validation rules to check that the input is not violating any of the configured constraints. You can treat it as a lower level guarantee that you're not instantiating objects that are broken.
|
8
|
+
|
9
|
+
All types support the constraints API, but not all constraints are suitable for a particular primitive, it's up to you to set up constraints that make sense.
|
10
|
+
|
11
|
+
Under the hood it uses [`dry-logic`](/gems/dry-logic) and all of its predicates are supported.
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
string = Types::String.constrained(min_size: 3)
|
15
|
+
|
16
|
+
string['foo']
|
17
|
+
# => "foo"
|
18
|
+
|
19
|
+
string['fo']
|
20
|
+
# => Dry::Types::ConstraintError: "fo" violates constraints
|
21
|
+
|
22
|
+
email = Types::String.constrained(
|
23
|
+
format: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
|
24
|
+
)
|
25
|
+
|
26
|
+
email["jane@doe.org"]
|
27
|
+
# => "jane@doe.org"
|
28
|
+
|
29
|
+
email["jane"]
|
30
|
+
# => Dry::Types::ConstraintError: "jane" violates constraints
|
31
|
+
```
|
@@ -0,0 +1,93 @@
|
|
1
|
+
---
|
2
|
+
title: Custom Types
|
3
|
+
layout: gem-single
|
4
|
+
name: dry-types
|
5
|
+
---
|
6
|
+
|
7
|
+
There are a bunch of helpers for building your own types based on existing classes and values. These helpers are automatically defined if you're imported types in a module.
|
8
|
+
|
9
|
+
### `Types.Instance`
|
10
|
+
|
11
|
+
`Types.Instance` builds a type that checks if a value has the given class.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
range_type = Types.Instance(Range)
|
15
|
+
range_type[1..2] # => 1..2
|
16
|
+
```
|
17
|
+
|
18
|
+
### `Types.Value`
|
19
|
+
|
20
|
+
`Types.Value` builds a type that checks a value for equality (using `==`).
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
valid = Types.Value('valid')
|
24
|
+
valid['valid'] # => 'valid'
|
25
|
+
valid['invalid']
|
26
|
+
# => Dry::Types::ConstraintError: "invalid" violates constraints (eql?("valid", "invalid") failed)
|
27
|
+
```
|
28
|
+
|
29
|
+
### `Types.Constant`
|
30
|
+
|
31
|
+
`Types.Constant` builds a type that checks a value for identity (using `equal?`).
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
valid = Types.Constant(:valid)
|
35
|
+
valid[:valid] # => :valid
|
36
|
+
valid[:invalid]
|
37
|
+
# => Dry::Types::ConstraintError: :invalid violates constraints (is?(:valid, :invalid) failed)
|
38
|
+
```
|
39
|
+
|
40
|
+
### `Types.Constructor`
|
41
|
+
|
42
|
+
`Types.Constructor` builds a new constructor type for the given class. By default uses the `new` method as a constructor.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
user_type = Types.Constructor(User)
|
46
|
+
|
47
|
+
# It is equivalent to User.new(name: 'John')
|
48
|
+
user_type[name: 'John']
|
49
|
+
|
50
|
+
# Using a block
|
51
|
+
user_type = Types.Constructor(User) { |values| User.new(values) }
|
52
|
+
```
|
53
|
+
|
54
|
+
### `Types.Nominal`
|
55
|
+
|
56
|
+
`Types.Nominal` wraps the given class with a simple definition without any behavior attached.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
int = Types.Nominal(Integer)
|
60
|
+
int[1] # => 1
|
61
|
+
|
62
|
+
# The type doesn't have any checks
|
63
|
+
int['one'] # => 'one'
|
64
|
+
```
|
65
|
+
|
66
|
+
### `Types.Hash`
|
67
|
+
|
68
|
+
`Types.Hash` builds a new hash schema.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
# In the full form
|
72
|
+
Types::Hash.schema(name: Types::String, age: Types::Coercible::Integer)
|
73
|
+
|
74
|
+
# Using Types.Hash()
|
75
|
+
Types.Hash(:permissive, name: Types::String, age: Types::Coercible::Integer)
|
76
|
+
```
|
77
|
+
|
78
|
+
### `Types.Array`
|
79
|
+
|
80
|
+
`Types.Array` is a shortcut for `Types::Array.of`
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
ListOfStrings = Types.Array(Types::String)
|
84
|
+
```
|
85
|
+
|
86
|
+
### `Types.Interface`
|
87
|
+
|
88
|
+
`Types.Interface` builds a type that checks a value responds to given methods.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
Callable = Types.Interface(:call)
|
92
|
+
Contact = Types.Interface(:name, :phone)
|
93
|
+
```
|