dry-types 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +378 -206
  3. data/LICENSE +17 -17
  4. data/README.md +14 -13
  5. data/dry-types.gemspec +27 -31
  6. data/lib/dry/types.rb +7 -11
  7. data/lib/dry/types/any.rb +2 -2
  8. data/lib/dry/types/array/member.rb +3 -3
  9. data/lib/dry/types/builder.rb +5 -1
  10. data/lib/dry/types/builder_methods.rb +22 -8
  11. data/lib/dry/types/coercions.rb +6 -0
  12. data/lib/dry/types/coercions/params.rb +1 -1
  13. data/lib/dry/types/compiler.rb +2 -2
  14. data/lib/dry/types/constrained.rb +2 -2
  15. data/lib/dry/types/constructor.rb +7 -34
  16. data/lib/dry/types/constructor/function.rb +17 -31
  17. data/lib/dry/types/core.rb +3 -1
  18. data/lib/dry/types/decorator.rb +3 -9
  19. data/lib/dry/types/default.rb +2 -2
  20. data/lib/dry/types/enum.rb +2 -2
  21. data/lib/dry/types/errors.rb +5 -5
  22. data/lib/dry/types/extensions.rb +4 -0
  23. data/lib/dry/types/extensions/maybe.rb +14 -14
  24. data/lib/dry/types/extensions/monads.rb +29 -0
  25. data/lib/dry/types/hash.rb +3 -2
  26. data/lib/dry/types/lax.rb +2 -5
  27. data/lib/dry/types/meta.rb +3 -3
  28. data/lib/dry/types/module.rb +3 -3
  29. data/lib/dry/types/nominal.rb +1 -1
  30. data/lib/dry/types/params.rb +6 -0
  31. data/lib/dry/types/predicate_inferrer.rb +197 -0
  32. data/lib/dry/types/predicate_registry.rb +34 -0
  33. data/lib/dry/types/primitive_inferrer.rb +97 -0
  34. data/lib/dry/types/printer.rb +7 -3
  35. data/lib/dry/types/result.rb +2 -2
  36. data/lib/dry/types/schema.rb +23 -2
  37. data/lib/dry/types/schema/key.rb +16 -3
  38. data/lib/dry/types/spec/types.rb +14 -1
  39. data/lib/dry/types/sum.rb +5 -5
  40. data/lib/dry/types/version.rb +1 -1
  41. metadata +26 -45
  42. data/.codeclimate.yml +0 -15
  43. data/.gitignore +0 -11
  44. data/.rspec +0 -2
  45. data/.travis.yml +0 -27
  46. data/.yardopts +0 -9
  47. data/CONTRIBUTING.md +0 -29
  48. data/Gemfile +0 -27
  49. data/Rakefile +0 -22
  50. data/benchmarks/hash_schemas.rb +0 -55
  51. data/benchmarks/lax_schema.rb +0 -15
  52. data/benchmarks/profile_invalid_input.rb +0 -15
  53. data/benchmarks/profile_lax_schema_valid.rb +0 -16
  54. data/benchmarks/profile_valid_input.rb +0 -15
  55. data/benchmarks/schema_valid_vs_invalid.rb +0 -21
  56. data/benchmarks/setup.rb +0 -17
@@ -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