dry-types 1.1.1 → 1.2.1

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -5
  3. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
  4. data/.github/ISSUE_TEMPLATE/---bug-report.md +34 -0
  5. data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
  6. data/.github/workflows/custom_ci.yml +76 -0
  7. data/.github/workflows/docsite.yml +34 -0
  8. data/.github/workflows/sync_configs.yml +34 -0
  9. data/.gitignore +1 -1
  10. data/.rspec +3 -1
  11. data/.rubocop.yml +34 -4
  12. data/CHANGELOG.md +69 -0
  13. data/CODE_OF_CONDUCT.md +13 -0
  14. data/CONTRIBUTING.md +2 -2
  15. data/Gemfile +11 -6
  16. data/LICENSE +17 -17
  17. data/docsite/source/array-with-member.html.md +13 -0
  18. data/docsite/source/built-in-types.html.md +116 -0
  19. data/docsite/source/constraints.html.md +31 -0
  20. data/docsite/source/custom-types.html.md +93 -0
  21. data/docsite/source/default-values.html.md +91 -0
  22. data/docsite/source/enum.html.md +69 -0
  23. data/docsite/source/extensions/maybe.html.md +57 -0
  24. data/docsite/source/extensions/monads.html.md +61 -0
  25. data/docsite/source/extensions.html.md +15 -0
  26. data/docsite/source/getting-started.html.md +57 -0
  27. data/docsite/source/hash-schemas.html.md +169 -0
  28. data/docsite/source/index.html.md +156 -0
  29. data/docsite/source/map.html.md +17 -0
  30. data/docsite/source/optional-values.html.md +35 -0
  31. data/docsite/source/sum.html.md +21 -0
  32. data/lib/dry/types/any.rb +2 -2
  33. data/lib/dry/types/array/member.rb +3 -3
  34. data/lib/dry/types/builder.rb +1 -1
  35. data/lib/dry/types/builder_methods.rb +18 -8
  36. data/lib/dry/types/compiler.rb +2 -2
  37. data/lib/dry/types/constrained.rb +1 -1
  38. data/lib/dry/types/constructor.rb +6 -33
  39. data/lib/dry/types/decorator.rb +3 -2
  40. data/lib/dry/types/enum.rb +1 -1
  41. data/lib/dry/types/extensions/monads.rb +29 -0
  42. data/lib/dry/types/extensions.rb +4 -0
  43. data/lib/dry/types/hash.rb +3 -2
  44. data/lib/dry/types/lax.rb +1 -1
  45. data/lib/dry/types/meta.rb +1 -1
  46. data/lib/dry/types/module.rb +3 -3
  47. data/lib/dry/types/params.rb +5 -0
  48. data/lib/dry/types/predicate_inferrer.rb +197 -0
  49. data/lib/dry/types/predicate_registry.rb +34 -0
  50. data/lib/dry/types/primitive_inferrer.rb +97 -0
  51. data/lib/dry/types/spec/types.rb +3 -1
  52. data/lib/dry/types/sum.rb +2 -2
  53. data/lib/dry/types/version.rb +1 -1
  54. data/lib/dry/types.rb +7 -2
  55. metadata +29 -4
  56. data/.travis.yml +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f4827f984803481533626b7ebe6e51fe6b5cf5da3691a7e0f9681c4d321bd1a
4
- data.tar.gz: 755af2027b59115fd97e1051bdea5eb400ca1a76cf39b19953538e4fb5bb28dc
3
+ metadata.gz: 6a22d275ce9f27a5be0edd1ce02714dbf571ee95abab2ab8e127b88e61317ac3
4
+ data.tar.gz: 8708d3ceb67ff3a726ae0363fe04fd08da440f3fdf7ae4e2f5632104fdf33810
5
5
  SHA512:
6
- metadata.gz: 18aa4a59b9fbe19721d65c57ca91f29b4f3935298e5947182953b9ffe92c7213fe4f209e55d3472a86d3d4645e8e0ccd200e5456af492026570b0f28f9255973
7
- data.tar.gz: e9b2886e43868b544ec1e4cb9c30949bbd3bec9dba1089dcd08c7ba36e456458a8746ea2537d5241c63322b38505ddc86fecda4035ab0f545e675cbc4188ba15
6
+ metadata.gz: 5ff0c69309f200eef77442aef6e9452046f75394c16b00f0be12cdbad04a8c34a1a02e87e0347fb1875fc0241a83f79e1b70576ad4d4e5202cde40257af3e3bb
7
+ data.tar.gz: 6eef147d7238f8ead4f254f37a0f018d5fc932ea3dd87bf334c06c3f0eb4110372078c4dcfad27c80a1dcfe161cc6955942d1daeffda6cd8980f3770b7a3c8b1
data/.codeclimate.yml CHANGED
@@ -1,9 +1,6 @@
1
- version: "2"
1
+ # this file is managed by dry-rb/devtools project
2
2
 
3
- prepare:
4
- fetch:
5
- - url: "https://raw.githubusercontent.com/dry-rb/devtools/master/.rubocop.yml"
6
- path: ".rubocop.yml"
3
+ version: "2"
7
4
 
8
5
  exclude_patterns:
9
6
  - "benchmarks/"
@@ -0,0 +1,10 @@
1
+ ---
2
+ name: "⚠️ Please don't ask for support via issues"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+
@@ -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
@@ -8,4 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  log/
11
- .rubocop.yml
11
+
data/.rspec CHANGED
@@ -1,2 +1,4 @@
1
1
  --color
2
- --require ./spec/spec_helper
2
+ --require spec_helper
3
+ --order random
4
+
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
1
3
  AllCops:
2
4
  TargetRubyVersion: 2.4
3
5
 
@@ -20,6 +22,9 @@ Style/StabbyLambdaParentheses:
20
22
  Style/FormatString:
21
23
  Enabled: false
22
24
 
25
+ Style/Documentation:
26
+ Enabled: false
27
+
23
28
  Layout/SpaceInLambdaLiteral:
24
29
  Enabled: false
25
30
 
@@ -40,9 +45,7 @@ Metrics/AbcSize:
40
45
  Max: 20
41
46
 
42
47
  Metrics/BlockLength:
43
- Enabled: true
44
- Exclude:
45
- - 'spec/**/*_spec.rb'
48
+ Enabled: false
46
49
 
47
50
  Metrics/CyclomaticComplexity:
48
51
  Enabled: true
@@ -55,5 +58,32 @@ Style/AccessModifierDeclarations:
55
58
  Enabled: false
56
59
 
57
60
  Style/BlockDelimiters:
58
- EnforcedStyle: semantic
61
+ Enabled: false
62
+
63
+ Layout/IndentFirstArrayElement:
64
+ EnforcedStyle: consistent
59
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,3 +1,72 @@
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
+
1
70
  # 1.1.1 2019-07-26
2
71
 
3
72
  ## Fixed
@@ -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](https://discourse.dry-rb.org) instead.
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
@@ -15,13 +17,16 @@ end
15
17
  group :tools do
16
18
  gem 'pry-byebug', platform: :mri
17
19
  gem 'rubocop'
20
+ gem 'ossy', github: 'solnic/ossy', branch: 'master'
18
21
  end
19
22
 
20
23
  group :benchmarks do
21
- gem 'attrio'
22
- gem 'benchmark-ips'
23
- gem 'dry-struct'
24
- gem 'fast_attributes'
25
- gem 'hotch'
26
- gem 'virtus'
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
27
32
  end
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2013-2014 Piotr Solnica
1
+ The MIT License (MIT)
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
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
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
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
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.
@@ -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
+ ```