dry-types 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +306 -225
  3. data/LICENSE +1 -1
  4. data/README.md +14 -12
  5. data/dry-types.gemspec +27 -31
  6. data/lib/dry/types.rb +0 -9
  7. data/lib/dry/types/builder.rb +4 -0
  8. data/lib/dry/types/constructor/function.rb +17 -31
  9. data/lib/dry/types/core.rb +3 -1
  10. data/lib/dry/types/decorator.rb +0 -7
  11. data/lib/dry/types/extensions/maybe.rb +14 -14
  12. data/lib/dry/types/lax.rb +1 -4
  13. data/lib/dry/types/meta.rb +2 -2
  14. data/lib/dry/types/params.rb +1 -0
  15. data/lib/dry/types/result.rb +2 -2
  16. data/lib/dry/types/schema.rb +23 -2
  17. data/lib/dry/types/schema/key.rb +11 -2
  18. data/lib/dry/types/spec/types.rb +11 -0
  19. data/lib/dry/types/sum.rb +2 -2
  20. data/lib/dry/types/version.rb +1 -1
  21. metadata +21 -59
  22. data/.codeclimate.yml +0 -12
  23. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  24. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -30
  25. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  26. data/.github/workflows/custom_ci.yml +0 -76
  27. data/.github/workflows/docsite.yml +0 -34
  28. data/.github/workflows/sync_configs.yml +0 -34
  29. data/.gitignore +0 -11
  30. data/.rspec +0 -4
  31. data/.rubocop.yml +0 -92
  32. data/.yardopts +0 -9
  33. data/CODE_OF_CONDUCT.md +0 -13
  34. data/CONTRIBUTING.md +0 -29
  35. data/Gemfile +0 -34
  36. data/Rakefile +0 -22
  37. data/benchmarks/hash_schemas.rb +0 -55
  38. data/benchmarks/lax_schema.rb +0 -15
  39. data/benchmarks/profile_invalid_input.rb +0 -15
  40. data/benchmarks/profile_lax_schema_valid.rb +0 -16
  41. data/benchmarks/profile_valid_input.rb +0 -15
  42. data/benchmarks/schema_valid_vs_invalid.rb +0 -21
  43. data/benchmarks/setup.rb +0 -17
  44. data/docsite/source/array-with-member.html.md +0 -13
  45. data/docsite/source/built-in-types.html.md +0 -116
  46. data/docsite/source/constraints.html.md +0 -31
  47. data/docsite/source/custom-types.html.md +0 -93
  48. data/docsite/source/default-values.html.md +0 -91
  49. data/docsite/source/enum.html.md +0 -69
  50. data/docsite/source/extensions.html.md +0 -15
  51. data/docsite/source/extensions/maybe.html.md +0 -57
  52. data/docsite/source/extensions/monads.html.md +0 -61
  53. data/docsite/source/getting-started.html.md +0 -57
  54. data/docsite/source/hash-schemas.html.md +0 -169
  55. data/docsite/source/index.html.md +0 -156
  56. data/docsite/source/map.html.md +0 -17
  57. data/docsite/source/optional-values.html.md +0 -35
  58. data/docsite/source/sum.html.md +0 -21
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- log/
11
-
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --order random
4
-
data/.rubocop.yml DELETED
@@ -1,92 +0,0 @@
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
90
-
91
- Style/DateTime:
92
- Enabled: false
data/.yardopts DELETED
@@ -1,9 +0,0 @@
1
- --title 'dry-types'
2
- --query '@api.text != "private"'
3
- --embed-mixins
4
- --output doc
5
- --readme README.md
6
- --files CHANGELOG.md
7
- --markup markdown
8
- --markup-provider=redcarpet
9
- lib/**/*.rb
data/CODE_OF_CONDUCT.md DELETED
@@ -1,13 +0,0 @@
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 DELETED
@@ -1,29 +0,0 @@
1
- # Issue Guidelines
2
-
3
- ## Reporting bugs
4
-
5
- If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
6
-
7
- ## Reporting feature requests
8
-
9
- Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
10
-
11
- ## Reporting questions, support requests, ideas, concerns etc.
12
-
13
- **PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
14
-
15
- # Pull Request Guidelines
16
-
17
- A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
18
-
19
- Other requirements:
20
-
21
- 1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
22
- 2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
23
- 3) Add API documentation if it's a new feature
24
- 4) Update API documentation if it changes an existing feature
25
- 5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
26
-
27
- # Asking for help
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) or join [our chat](https://dry-rb.zulipchat.com).
data/Gemfile DELETED
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
- gemspec
8
-
9
- gem 'dry-logic', github: 'dry-rb/dry-logic', branch: 'master' if ENV['DRY_LOGIC_FROM_MASTER'].eql?('true')
10
-
11
- group :test do
12
- platform :mri do
13
- gem 'simplecov', require: false
14
- end
15
-
16
- gem 'dry-struct'
17
- end
18
-
19
- group :tools do
20
- gem 'pry-byebug', platform: :mri
21
- gem 'rubocop'
22
- gem 'ossy', github: 'solnic/ossy', branch: 'master'
23
- end
24
-
25
- group :benchmarks do
26
- platform :mri do
27
- gem 'attrio'
28
- gem 'benchmark-ips'
29
- gem 'dry-struct'
30
- gem 'fast_attributes'
31
- gem 'hotch'
32
- gem 'virtus'
33
- end
34
- end
data/Rakefile DELETED
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- task :run_specs do
7
- require 'rspec/core'
8
-
9
- types_result = RSpec::Core::Runner.run(['spec/dry'])
10
- RSpec.clear_examples
11
-
12
- Dry::Types.load_extensions(:maybe)
13
- ext_result = RSpec::Core::Runner.run(['spec'])
14
-
15
- exit [types_result, ext_result].max
16
- end
17
-
18
- task default: :run_specs
19
-
20
- require 'yard'
21
- require 'yard/rake/yardoc_task'
22
- YARD::Rake::YardocTask.new(:doc)
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift('lib')
4
-
5
- require 'bundler/setup'
6
- require 'dry-types'
7
-
8
- module SchemaBench
9
- def self.hash_schema(type)
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,
17
- city: Dry::Types['nominal.string'],
18
- street: Dry::Types['nominal.string']
19
- )
20
- )
21
- end
22
-
23
- private_class_method(:hash_schema)
24
-
25
- SCHEMAS =
26
- Dry::Types::Hash
27
- .public_instance_methods(false)
28
- .map { |schema_type| [schema_type, hash_schema(schema_type)] }
29
- .to_h
30
-
31
- INPUT = {
32
- email: 'jane@doe.org',
33
- age: '20',
34
- admin: '1',
35
- address: { city: 'NYC', street: 'Street 1/2' }
36
- }.freeze
37
- end
38
-
39
- require 'benchmark/ips'
40
-
41
- Benchmark.ips do |x|
42
- SchemaBench::SCHEMAS.each do |schema_type, schema|
43
- x.report("#{schema_type}#call") do
44
- schema.call(SchemaBench::INPUT)
45
- end
46
- end
47
-
48
- SchemaBench::SCHEMAS.each do |schema_type, schema|
49
- x.report("#{schema_type}#try") do
50
- schema.try(SchemaBench::INPUT)
51
- end
52
- end
53
-
54
- x.compare!
55
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'setup'
4
-
5
- schema = Dry::Types['params.hash'].schema(
6
- email?: 'string',
7
- age?: 'params.integer'
8
- ).lax
9
-
10
- params = { email: 'jane@doe.org', age: '19' }
11
-
12
- Benchmark.ips do |x|
13
- x.report("valid input") { schema.(params) }
14
- x.compare!
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'setup'
4
-
5
- INVALID_INPUT = {
6
- name: :John,
7
- age: '20',
8
- email: nil
9
- }.freeze
10
-
11
- profile do
12
- 10_000.times do
13
- PersonSchema.(INVALID_INPUT)
14
- end
15
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'setup'
4
-
5
- Schema = Dry::Types['params.hash'].schema(
6
- email?: 'string',
7
- age?: 'coercible.integer'
8
- ).lax
9
-
10
- ValidInput = { email: 'jane@doe.org', age: '19' }.freeze
11
-
12
- profile do
13
- 10_000.times do
14
- Schema.(ValidInput)
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'setup'
4
-
5
- VALID_INPUT = {
6
- name: 'John',
7
- age: 20,
8
- email: 'john@doe.com'
9
- }.freeze
10
-
11
- profile do
12
- 10_000.times do
13
- PersonSchema.(VALID_INPUT)
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'setup'
4
-
5
- VALID_INPUT = {
6
- name: 'John',
7
- age: 20,
8
- email: 'john@doe.com'
9
- }
10
-
11
- INVALID_INPUT = {
12
- name: :John,
13
- age: '20',
14
- email: nil
15
- }
16
-
17
- Benchmark.ips do |x|
18
- x.report("valid input") { PersonSchema.(VALID_INPUT) }
19
- x.report("invalid input") { PersonSchema.(INVALID_INPUT) }
20
- x.compare!
21
- end
data/benchmarks/setup.rb DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'benchmark/ips'
4
- require 'hotch'
5
- ENV['HOTCH_VIEWER'] ||= 'open'
6
-
7
- require 'dry/types'
8
-
9
- PersonSchema = Dry::Types['hash'].schema(
10
- name: 'string',
11
- age: 'integer',
12
- email: 'string'
13
- ).lax
14
-
15
- def profile(&block)
16
- Hotch(filter: 'Dry', &block)
17
- end
@@ -1,13 +0,0 @@
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
- ```
@@ -1,116 +0,0 @@
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.