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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a22d275ce9f27a5be0edd1ce02714dbf571ee95abab2ab8e127b88e61317ac3
|
4
|
+
data.tar.gz: 8708d3ceb67ff3a726ae0363fe04fd08da440f3fdf7ae4e2f5632104fdf33810
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ff0c69309f200eef77442aef6e9452046f75394c16b00f0be12cdbad04a8c34a1a02e87e0347fb1875fc0241a83f79e1b70576ad4d4e5202cde40257af3e3bb
|
7
|
+
data.tar.gz: 6eef147d7238f8ead4f254f37a0f018d5fc932ea3dd87bf334c06c3f0eb4110372078c4dcfad27c80a1dcfe161cc6955942d1daeffda6cd8980f3770b7a3c8b1
|
data/.codeclimate.yml
CHANGED
@@ -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.
|
@@ -0,0 +1,76 @@
|
|
1
|
+
name: ci
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
paths:
|
6
|
+
- .github/workflows/ci.yml
|
7
|
+
- lib/**
|
8
|
+
- spec/**
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
tests-mri:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
fail-fast: false
|
15
|
+
matrix:
|
16
|
+
ruby: ["2.6.x", "2.5.x", "2.4.x"]
|
17
|
+
dry_logic_from_master: ["true", "false"]
|
18
|
+
include:
|
19
|
+
- ruby: "2.6.x"
|
20
|
+
dry_logic_from_master: "false"
|
21
|
+
coverage: "true"
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v1
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: actions/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{matrix.ruby}}
|
28
|
+
- name: Download test reporter
|
29
|
+
if: "matrix.coverage == 'true'"
|
30
|
+
run: |
|
31
|
+
mkdir -p tmp/
|
32
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
|
33
|
+
chmod +x ./tmp/cc-test-reporter
|
34
|
+
./tmp/cc-test-reporter before-build
|
35
|
+
- name: Run all tests
|
36
|
+
env:
|
37
|
+
COVERAGE: ${{matrix.coverage}}
|
38
|
+
DRY_LOGIC_FROM_MASTER: ${{matrix.dry_logic_from_master}}
|
39
|
+
run: |
|
40
|
+
gem install bundler
|
41
|
+
bundle install --jobs 4 --retry 3 --without tools docs
|
42
|
+
bundle exec rake
|
43
|
+
- name: Send coverage results
|
44
|
+
if: "matrix.coverage == 'true'"
|
45
|
+
env:
|
46
|
+
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
|
47
|
+
GIT_COMMIT_SHA: ${{github.sha}}
|
48
|
+
GIT_BRANCH: ${{github.ref}}
|
49
|
+
GIT_COMMITTED_AT: ${{github.event.head_commit.timestamp}}
|
50
|
+
run: |
|
51
|
+
GIT_BRANCH=`ruby -e "puts ENV['GITHUB_REF'].split('/', 3).last"` \
|
52
|
+
GIT_COMMITTED_AT=`ruby -r time -e "puts Time.iso8601(ENV['GIT_COMMITTED_AT']).to_i"` \
|
53
|
+
./tmp/cc-test-reporter after-build
|
54
|
+
|
55
|
+
tests-others:
|
56
|
+
runs-on: ubuntu-latest
|
57
|
+
strategy:
|
58
|
+
fail-fast: false
|
59
|
+
matrix:
|
60
|
+
image: ["jruby:9.2.8", "ruby:rc"]
|
61
|
+
dry_logic_from_master: ["true", "false"]
|
62
|
+
container:
|
63
|
+
image: ${{matrix.image}}
|
64
|
+
steps:
|
65
|
+
- uses: actions/checkout@v1
|
66
|
+
- name: Install git
|
67
|
+
run: |
|
68
|
+
apt-get update
|
69
|
+
apt-get install -y --no-install-recommends git
|
70
|
+
- name: Run all tests
|
71
|
+
env:
|
72
|
+
DRY_LOGIC_FROM_MASTER: ${{matrix.dry_logic_from_master}}
|
73
|
+
run: |
|
74
|
+
gem install bundler
|
75
|
+
bundle install --jobs 4 --retry 3 --without tools docs
|
76
|
+
bundle exec rspec
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
name: docsite
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
paths:
|
8
|
+
- docsite/**
|
9
|
+
- .github/workflows/docsite.yml
|
10
|
+
branches:
|
11
|
+
- master
|
12
|
+
- release-**
|
13
|
+
tags:
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
update-docs:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v1
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: actions/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: "2.6.x"
|
24
|
+
- name: Install dependencies
|
25
|
+
run: |
|
26
|
+
gem install bundler
|
27
|
+
bundle install --jobs 4 --retry 3 --without benchmarks sql
|
28
|
+
- name: Symlink ossy
|
29
|
+
run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
|
30
|
+
- name: Trigger dry-rb.org deploy
|
31
|
+
env:
|
32
|
+
GITHUB_LOGIN: dry-bot
|
33
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
34
|
+
run: bin/ossy github workflow dry-rb/dry-rb.org ci
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
name: sync_configs
|
4
|
+
|
5
|
+
on:
|
6
|
+
repository_dispatch:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
sync-configs:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
if: github.event.action == 'sync_configs'
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v1
|
14
|
+
- name: Update configuration files from devtools
|
15
|
+
env:
|
16
|
+
GITHUB_LOGIN: dry-bot
|
17
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
18
|
+
run: |
|
19
|
+
git clone https://github.com/dry-rb/devtools.git tmp/devtools
|
20
|
+
|
21
|
+
if [ -f ".github/workflows/custom_ci.yml" ]; then
|
22
|
+
rsync -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
|
23
|
+
else
|
24
|
+
rsync -av tmp/devtools/shared/ . ;
|
25
|
+
fi
|
26
|
+
|
27
|
+
git config --local user.email "dry-bot@dry-rb.org"
|
28
|
+
git config --local user.name "dry-bot"
|
29
|
+
git add -A
|
30
|
+
git commit -m "[devtools] config sync" || echo "nothing changed"
|
31
|
+
- name: Push changes
|
32
|
+
uses: ad-m/github-push-action@master
|
33
|
+
with:
|
34
|
+
github_token: ${{ secrets.GH_PAT }}
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.4
|
5
|
+
|
6
|
+
Style/EachWithObject:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: single_quotes
|
12
|
+
|
13
|
+
Style/Alias:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/LambdaCall:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/StabbyLambdaParentheses:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/FormatString:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/Documentation:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Layout/SpaceInLambdaLiteral:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Layout/MultilineMethodCallIndentation:
|
32
|
+
Enabled: true
|
33
|
+
EnforcedStyle: indented
|
34
|
+
|
35
|
+
Metrics/LineLength:
|
36
|
+
Max: 100
|
37
|
+
|
38
|
+
Metrics/MethodLength:
|
39
|
+
Max: 22
|
40
|
+
|
41
|
+
Metrics/ClassLength:
|
42
|
+
Max: 150
|
43
|
+
|
44
|
+
Metrics/AbcSize:
|
45
|
+
Max: 20
|
46
|
+
|
47
|
+
Metrics/BlockLength:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Metrics/CyclomaticComplexity:
|
51
|
+
Enabled: true
|
52
|
+
Max: 10
|
53
|
+
|
54
|
+
Lint/BooleanSymbol:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/AccessModifierDeclarations:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/BlockDelimiters:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Layout/IndentFirstArrayElement:
|
64
|
+
EnforcedStyle: consistent
|
65
|
+
|
66
|
+
Style/ClassAndModuleChildren:
|
67
|
+
Exclude:
|
68
|
+
- "spec/**/*_spec.rb"
|
69
|
+
|
70
|
+
Lint/HandleExceptions:
|
71
|
+
Exclude:
|
72
|
+
- "spec/spec_helper.rb"
|
73
|
+
|
74
|
+
Naming/FileName:
|
75
|
+
Exclude:
|
76
|
+
- "lib/dry-*.rb"
|
77
|
+
|
78
|
+
Style/SymbolArray:
|
79
|
+
Exclude:
|
80
|
+
- "spec/**/*_spec.rb"
|
81
|
+
|
82
|
+
Style/ConditionalAssignment:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
Naming/MethodName:
|
86
|
+
Enabled: false
|
87
|
+
|
88
|
+
Style/AsciiComments:
|
89
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,126 @@
|
|
1
|
+
# 1.2.1 2019-11-07
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
- Fix keyword warnings reported by Ruby 2.7 (flash-gordon)
|
6
|
+
- Error type in failing case in `Array::Member` (esparta)
|
7
|
+
|
8
|
+
[Compare v1.2.0...v1.2.1](https://github.com/dry-rb/dry-types/compare/v1.2.0...v1.2.1)
|
9
|
+
|
10
|
+
# 1.2.0 2019-10-06
|
11
|
+
|
12
|
+
## Changed
|
13
|
+
|
14
|
+
- `Dry::Types.[]` used to work with classes, now it's deprecated (flash-gordon)
|
15
|
+
|
16
|
+
## Fixed
|
17
|
+
|
18
|
+
- Bug with using a `Bool`-named struct as a schema key (flash-gordon)
|
19
|
+
- A bunch of issues related to using `meta` on complex types (flash-gordon)
|
20
|
+
- `Types.Constructor(...)` returns a `Types::Array` as it should (flash-gordon)
|
21
|
+
|
22
|
+
## Added
|
23
|
+
|
24
|
+
- `Optional::Params` types that coerce empty strings to `nil` (flash-gordon)
|
25
|
+
```ruby
|
26
|
+
Dry::Types['optional.params.integer'].('') # => nil
|
27
|
+
Dry::Types['optional.params.integer'].('140') # => 140
|
28
|
+
Dry::Types['optional.params.integer'].('asd') # => exception!
|
29
|
+
```
|
30
|
+
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.
|
31
|
+
- Predicate inferrer was ported from dry-schema (authored by solnic)
|
32
|
+
```ruby
|
33
|
+
require 'dry/types/predicate_inferrer'
|
34
|
+
Dry::Types::PredicateInferrer.new[Types::String]
|
35
|
+
# => [:str?]
|
36
|
+
Dry::Types::PredicateInferrer.new[Types::String | Types::Integer]
|
37
|
+
# => [[[:str?], [:int?]]]
|
38
|
+
```
|
39
|
+
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.
|
40
|
+
- Primitive inferrer was ported from dry-schema (authored by solnic)
|
41
|
+
```ruby
|
42
|
+
require 'dry/types/primitive_inferrer'
|
43
|
+
Dry::Types::PrimitiveInferrer.new[Types::String]
|
44
|
+
# => [String]
|
45
|
+
Dry::Types::PrimitiveInferrer.new[Types::String | Types::Integer]
|
46
|
+
# => [String, Integer]
|
47
|
+
Dry::Types::PrimitiveInferrer.new[Types::String.optional]
|
48
|
+
# => [NilClass, String]
|
49
|
+
```
|
50
|
+
The primitive inferrer should be stable by now, you can rely on it.
|
51
|
+
- 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)
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Types = Dry.Types
|
55
|
+
Dry::Types.load_extensions(:monads)
|
56
|
+
|
57
|
+
class AddTen
|
58
|
+
include Dry::Monads[:result, :do]
|
59
|
+
|
60
|
+
def call(input)
|
61
|
+
integer = yield Types::Coercible::Integer.try(input)
|
62
|
+
|
63
|
+
Success(integer + 10)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
[Compare v1.1.1...v1.2.0](https://github.com/dry-rb/dry-types/compare/v1.1.1...v1.2.0)
|
69
|
+
|
70
|
+
# 1.1.1 2019-07-26
|
71
|
+
|
72
|
+
## Fixed
|
73
|
+
|
74
|
+
- A bug where meta was lost for lax array types (flash-gordon)
|
75
|
+
|
76
|
+
[Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-types/compare/v1.1.0...v1.1.1)
|
77
|
+
|
78
|
+
# 1.1.0 2019-07-02
|
79
|
+
|
80
|
+
## Added
|
81
|
+
|
82
|
+
- New builder method `Interface` constructs a type which accepts objects that respond to the given methods (waiting-for-dev)
|
83
|
+
```ruby
|
84
|
+
Types = Dry.Types()
|
85
|
+
Types::Callable = Types.Interface(:call)
|
86
|
+
Types::Callable.valid?(Object.new) # => false
|
87
|
+
Types::Callable.valid?(proc {}) # => true
|
88
|
+
```
|
89
|
+
- New types: `coercible.symbol`, `params.symbol`, and `json.symbol`, all use `.to_sym` for coercion (waiting-for-dev)
|
90
|
+
|
91
|
+
## Fixed
|
92
|
+
|
93
|
+
- Converting schema keys to maybe types (flash-gordon)
|
94
|
+
- Using `Schema#key` and `Array#member` on constuctors (flash-gordon)
|
95
|
+
- Using `meta(omittable: true)` within `transform_types` works again but produces a warning, please migrate to `.omittable` or `.required(false)` (flash-gordon)
|
96
|
+
- Bug with a constructror defined on top of enum (flash-gordon)
|
97
|
+
|
98
|
+
[Compare v1.0.1...v1.1.0](https://github.com/dry-rb/dry-types/compare/v1.0.1...v1.1.0)
|
99
|
+
|
100
|
+
# 1.0.1 2019-06-04
|
101
|
+
|
102
|
+
## Added
|
103
|
+
|
104
|
+
- In a case of failure the constructor block can now pass a different value (flash-gordon)
|
105
|
+
```ruby
|
106
|
+
not_empty_string = Types::String.constructor do |value, &failure|
|
107
|
+
value.strip.empty? ? failure.(nil) : value.strip
|
108
|
+
end
|
109
|
+
not_empty_string.(' ') { |v| v } # => nil
|
110
|
+
not_empty_string.lax.(' ') # => nil
|
111
|
+
not_empty_string.lax.(' foo ') # => "foo"
|
112
|
+
```
|
113
|
+
- `Schema#strict` now accepts an boolean argument. If `fales` is passed this will turn a strict schema into a non-strict one (flash-gordon)
|
114
|
+
|
115
|
+
[Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-types/compare/v1.0.0...v1.0.1)
|
116
|
+
|
1
117
|
# 1.0.0 2019-04-23
|
2
118
|
|
3
119
|
## Changed
|
4
120
|
|
5
121
|
- [BREAKING] Behavior of built-in constructor types was changed to be more strict. They will always raise an error on failed coercion (flash-gordon)
|
6
122
|
Compare:
|
123
|
+
|
7
124
|
```ruby
|
8
125
|
# 0.15.0
|
9
126
|
Types::Params::Integer.('foo')
|
@@ -19,7 +136,9 @@
|
|
19
136
|
```ruby
|
20
137
|
Types::Params::Integer.('foo') { :invalid } # => :invalid
|
21
138
|
```
|
139
|
+
|
22
140
|
This makes work with coercions more straightforward and way faster.
|
141
|
+
|
23
142
|
- [BREAKING] Safe types were renamed to Lax, this name better serves their purpose. The previous name is available but prints a warning (flash-gordon)
|
24
143
|
- [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)
|
25
144
|
- 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)
|
@@ -30,7 +149,7 @@
|
|
30
149
|
|
31
150
|
## Added
|
32
151
|
|
33
|
-
- API for custom constructor types was enhanced. If you pass your own callable to `.constructor` it can have a block in its signature. If a block is passed, you must call it on
|
152
|
+
- API for custom constructor types was enhanced. If you pass your own callable to `.constructor` it can have a block in its signature. If a block is passed, you must call it on failed coercion, otherwise raise a type coercion error (flash-gordon)
|
34
153
|
Example:
|
35
154
|
```ruby
|
36
155
|
proc do |input, &block|
|
@@ -142,6 +261,7 @@
|
|
142
261
|
)
|
143
262
|
```
|
144
263
|
- Key types have API for making keys omittable and back (flash-gordon)
|
264
|
+
|
145
265
|
```ruby
|
146
266
|
# defining a base schema with optional keys
|
147
267
|
lax_hash = Dry::Types['hash'].with_type_transform { |key| key.required(false) }
|
@@ -151,8 +271,10 @@
|
|
151
271
|
# keys in user_schema are not required
|
152
272
|
user_schema = lax_hash.schema(name: 'string', age: 'integer')
|
153
273
|
```
|
274
|
+
|
154
275
|
- `Type#optional?` now recognizes more cases where `nil` is an allowed value (flash-gordon)
|
155
276
|
- `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)
|
277
|
+
|
156
278
|
```ruby
|
157
279
|
to_int = Types::Coercible::Integer
|
158
280
|
inc = to_int.append { |x| x + 2 }
|
@@ -161,6 +283,7 @@
|
|
161
283
|
inc = to_int.prepend { |x| x + "2" }
|
162
284
|
inc.("1") # => "1" -> "12" -> 12
|
163
285
|
```
|
286
|
+
|
164
287
|
- Partial schema application for cases when you want to validate only a subset of keys (flash-gordon)
|
165
288
|
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.
|
166
289
|
```ruby
|
@@ -172,14 +295,15 @@
|
|
172
295
|
|
173
296
|
## Fixed
|
174
297
|
|
175
|
-
|
176
|
-
|
298
|
+
- `Hash::Map` now behaves as a constrained type if its values are constrained (flash-gordon)
|
299
|
+
- `coercible.integer` now doesn't blow up on invalid strings (exterm)
|
177
300
|
|
178
301
|
[Compare v0.14.0...v0.15.0](https://github.com/dry-rb/dry-types/compare/v0.14.0...v0.15.0)
|
179
302
|
|
180
303
|
# v0.14.1 2019-03-25
|
181
304
|
|
182
305
|
## Fixed
|
306
|
+
|
183
307
|
- `coercible.integer` now doesn't blow up on invalid strings (exterm)
|
184
308
|
|
185
309
|
[Compare v0.14.0...v0.14.1](https://github.com/dry-rb/dry-types/compare/v0.14.0...v0.14.1)
|