dry-types 1.5.1 → 1.7.2

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/LICENSE +1 -1
  4. data/README.md +7 -13
  5. data/dry-types.gemspec +19 -18
  6. data/lib/dry/types/array/constructor.rb +0 -2
  7. data/lib/dry/types/array/member.rb +1 -3
  8. data/lib/dry/types/array.rb +0 -3
  9. data/lib/dry/types/builder.rb +43 -14
  10. data/lib/dry/types/builder_methods.rb +1 -1
  11. data/lib/dry/types/coercions/params.rb +4 -3
  12. data/lib/dry/types/compat.rb +1 -0
  13. data/lib/dry/types/compiler.rb +1 -3
  14. data/lib/dry/types/composition.rb +152 -0
  15. data/lib/dry/types/constrained.rb +0 -5
  16. data/lib/dry/types/constraints.rb +3 -7
  17. data/lib/dry/types/constructor/function.rb +8 -9
  18. data/lib/dry/types/constructor.rb +4 -10
  19. data/lib/dry/types/container.rb +1 -3
  20. data/lib/dry/types/core.rb +2 -3
  21. data/lib/dry/types/decorator.rb +0 -2
  22. data/lib/dry/types/default.rb +3 -6
  23. data/lib/dry/types/enum.rb +0 -3
  24. data/lib/dry/types/errors.rb +13 -1
  25. data/lib/dry/types/extensions/maybe.rb +8 -5
  26. data/lib/dry/types/extensions/monads.rb +7 -2
  27. data/lib/dry/types/fn_container.rb +0 -2
  28. data/lib/dry/types/hash/constructor.rb +2 -4
  29. data/lib/dry/types/hash.rb +1 -6
  30. data/lib/dry/types/implication.rb +66 -0
  31. data/lib/dry/types/intersection.rb +108 -0
  32. data/lib/dry/types/lax.rb +1 -4
  33. data/lib/dry/types/map.rb +9 -3
  34. data/lib/dry/types/module.rb +18 -9
  35. data/lib/dry/types/nominal.rb +2 -13
  36. data/lib/dry/types/predicate_inferrer.rb +8 -9
  37. data/lib/dry/types/predicate_registry.rb +7 -7
  38. data/lib/dry/types/primitive_inferrer.rb +0 -2
  39. data/lib/dry/types/printer/composition.rb +44 -0
  40. data/lib/dry/types/printer.rb +116 -131
  41. data/lib/dry/types/result.rb +0 -2
  42. data/lib/dry/types/schema/key.rb +1 -4
  43. data/lib/dry/types/schema.rb +6 -4
  44. data/lib/dry/types/sum.rb +3 -95
  45. data/lib/dry/types/type.rb +1 -3
  46. data/lib/dry/types/version.rb +1 -1
  47. data/lib/dry/types.rb +49 -22
  48. metadata +32 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c7c872991cdfc4269f8de895e51cd19b129f6ef86fb78b48ff5ca5bb1e811d8
4
- data.tar.gz: b3600454a14b4dde65512f8c55f4c2a9ec1e9293d45364cde763bb0e1185fa9b
3
+ metadata.gz: 12b751a4799c67217dd1540dacc45a70ce51dab53441ec64e575f74a520e0eb6
4
+ data.tar.gz: e50e85513f68af8f0b98f5af707c2e82826c7daed237fba9ca014b96fc4e4754
5
5
  SHA512:
6
- metadata.gz: 5f0286b20cd4c40478587e083ff4ef7fb6bb39e66ee01864c7f5710697f30378742899ae509181be215096cf76b26d2c1aa14e4b1f2bd651058911e201d5281f
7
- data.tar.gz: 2a1ae064396c3074bf28d90fe94867b62b2c787ea0798a7f934bc81b2232b46616f7ee71ad7caaa4612712f1ff306f9f255969b0e4ad67f28e12925fd77dd658
6
+ metadata.gz: c7247fc6a64c97967a83de7613f298d25137c4d03ae9afa79929255cca792dcb6a9f7203f4cdefb942b662c7ec7a32d0386a005c8e6e19ecfa03d37d802d2877
7
+ data.tar.gz: 2a54fd10714b4a5a74e7026de501c9a74f4378890ed4e39f98f9b163eb23ebfd28d27d85165e18a68aa8603149df2c8d56eabef99f36d26c56f6e60676fa3e3b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.7.2 2024-01-05
4
+
5
+
6
+ ### Fixed
7
+
8
+ - Fixed BigDecimal warning due to not being required in gemspec (@bkuhlmann in #464)
9
+
10
+
11
+ [Compare v1.7.1...v1.7.2](https://github.com/dry-rb/dry-types/compare/v1.7.1...v1.7.2)
12
+
13
+ ## 1.7.1 2023-02-17
14
+
15
+
16
+ ### Fixed
17
+
18
+ - Warning from jruby about overwritten keyword (@flash-gordon + @klobuczek in #454)
19
+
20
+
21
+ [Compare v1.7.0...v1.7.1](https://github.com/dry-rb/dry-types/compare/v1.7.0...v1.7.1)
22
+
23
+ ## 1.7.0 2022-11-04
24
+
25
+
26
+ ### Changed
27
+
28
+ - This version is compatible with recently released dry-rb dependencies (@flash-gordon)
29
+ - Updated to dry-core 1.0 (@flash-gordon + @solnic)
30
+ - Dependency on dry-container was dropped (@flash-gordon)
31
+
32
+ [Compare v1.6.1...v1.7.0](https://github.com/dry-rb/dry-types/compare/v1.6.1...v1.7.0)
33
+
34
+ ## 1.6.1 2022-10-15
35
+
36
+
37
+ ### Changed
38
+
39
+ - Fix issues with internal const_missing and Inflector/Module constants (@flash-gordon + @solnic)
40
+
41
+ [Compare v1.6.0...v1.6.1](https://github.com/dry-rb/dry-types/compare/v1.6.0...v1.6.1)
42
+
43
+ ## 1.6.0 2022-10-15
44
+
45
+
46
+ ### Changed
47
+
48
+ - Optimize `PredicateRegistry` for Ruby 2.7+ (see #420 for more details) (@casperisfine)
49
+ - Use zeitwerk for auto-loading (@flash-gordon)
50
+
51
+ [Compare v1.5.1...v1.6.0](https://github.com/dry-rb/dry-types/compare/v1.5.1...v1.6.0)
52
+
3
53
  ## 1.5.1 2021-02-16
4
54
 
5
55
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 dry-rb team
3
+ Copyright (c) 2015-2023 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,28 +1,22 @@
1
+ <!--- this file is synced from dry-rb/template-gem project -->
2
+
1
3
  [gem]: https://rubygems.org/gems/dry-types
2
4
  [actions]: https://github.com/dry-rb/dry-types/actions
3
- [codacy]: https://www.codacy.com/gh/dry-rb/dry-types
4
- [chat]: https://dry-rb.zulipchat.com
5
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-types
6
-
7
- # dry-types [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
5
 
9
- [![Gem Version](https://badge.fury.io/rb/dry-types.svg)][gem]
10
- [![CI Status](https://github.com/dry-rb/dry-types/workflows/ci/badge.svg)][actions]
11
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f2d71613195f4da993acb9ac9d6ea336)][codacy]
12
- [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f2d71613195f4da993acb9ac9d6ea336)][codacy]
13
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-types.svg?branch=master)][inchpages]
6
+ # dry-types [![Gem Version](https://badge.fury.io/rb/dry-types.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-types/workflows/CI/badge.svg)][actions]
14
7
 
15
8
  ## Links
16
9
 
17
- * [User documentation](http://dry-rb.org/gems/dry-types)
10
+ * [User documentation](https://dry-rb.org/gems/dry-types)
18
11
  * [API documentation](http://rubydoc.info/gems/dry-types)
12
+ * [Forum](https://discourse.dry-rb.org)
19
13
 
20
14
  ## Supported Ruby versions
21
15
 
22
16
  This library officially supports the following Ruby versions:
23
17
 
24
- * MRI >= `2.5`
25
- * jruby >= `9.2`
18
+ * MRI `>= 3.0`
19
+ * jruby `>= 9.4` (not tested on CI)
26
20
 
27
21
  ## License
28
22
 
data/dry-types.gemspec CHANGED
@@ -1,41 +1,42 @@
1
1
  # frozen_string_literal: true
2
- # this file is managed by dry-rb/devtools project
3
2
 
4
- lib = File.expand_path('lib', __dir__)
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
5
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
- require 'dry/types/version'
7
+ require "dry/types/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
- spec.name = 'dry-types'
10
+ spec.name = "dry-types"
10
11
  spec.authors = ["Piotr Solnica"]
11
12
  spec.email = ["piotr.solnica@gmail.com"]
12
- spec.license = 'MIT'
13
+ spec.license = "MIT"
13
14
  spec.version = Dry::Types::VERSION.dup
14
15
 
15
16
  spec.summary = "Type system for Ruby supporting coercions, constraints and complex types like structs, value objects, enums etc"
16
17
  spec.description = spec.summary
17
- spec.homepage = 'https://dry-rb.org/gems/dry-types'
18
+ spec.homepage = "https://dry-rb.org/gems/dry-types"
18
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-types.gemspec", "lib/**/*"]
19
- spec.bindir = 'bin'
20
+ spec.bindir = "bin"
20
21
  spec.executables = []
21
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
22
23
 
23
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-types/blob/master/CHANGELOG.md'
25
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-types'
26
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-types/issues'
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-types/blob/main/CHANGELOG.md"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-types"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-types/issues"
27
28
 
28
- spec.required_ruby_version = ">= 2.5.0"
29
+ spec.required_ruby_version = ">= 3.0"
29
30
 
30
31
  # to update dependencies edit project.yml
32
+ spec.add_runtime_dependency "bigdecimal", "~> 3.0"
31
33
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
32
- spec.add_runtime_dependency "dry-container", "~> 0.3"
33
- spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
34
- spec.add_runtime_dependency "dry-inflector", "~> 0.1", ">= 0.1.2"
35
- spec.add_runtime_dependency "dry-logic", "~> 1.0", ">= 1.0.2"
34
+ spec.add_runtime_dependency "dry-core", "~> 1.0"
35
+ spec.add_runtime_dependency "dry-inflector", "~> 1.0"
36
+ spec.add_runtime_dependency "dry-logic", "~> 1.4"
37
+ spec.add_runtime_dependency "zeitwerk", "~> 2.6"
36
38
 
37
39
  spec.add_development_dependency "bundler"
38
- spec.add_development_dependency "dry-monads", "~> 1.0"
39
40
  spec.add_development_dependency "rake"
40
41
  spec.add_development_dependency "rspec"
41
42
  spec.add_development_dependency "yard"
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/types/constructor"
4
-
5
3
  module Dry
6
4
  module Types
7
5
  # @api public
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/types/array/constructor"
4
-
5
3
  module Dry
6
4
  module Types
7
5
  class Array < Nominal
@@ -72,7 +70,7 @@ module Dry
72
70
  # @return [Result,Logic::Result]
73
71
  #
74
72
  # @api public
75
- def try(input, &block)
73
+ def try(input, &block) # rubocop:disable Metrics/PerceivedComplexity
76
74
  if primitive?(input)
77
75
  output = []
78
76
 
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/types/array/member"
4
- require "dry/types/array/constructor"
5
-
6
3
  module Dry
7
4
  module Types
8
5
  # Array type can be used to define an array with optional member type
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/core/deprecations"
4
-
5
3
  module Dry
6
4
  module Types
7
5
  # Common API for building types and composition
8
6
  #
9
7
  # @api public
8
+ # rubocop:disable Metrics/ModuleLength
10
9
  module Builder
11
10
  include Dry::Core::Constants
12
11
 
@@ -32,8 +31,29 @@ module Dry
32
31
  #
33
32
  # @api private
34
33
  def |(other)
35
- klass = constrained? && other.constrained? ? Sum::Constrained : Sum
36
- klass.new(self, other)
34
+ compose(other, Sum)
35
+ end
36
+
37
+ # Compose two types into an Intersection type
38
+ #
39
+ # @param [Type] other
40
+ #
41
+ # @return [Intersection, Intersection::Constrained]
42
+ #
43
+ # @api private
44
+ def &(other)
45
+ compose(other, Intersection)
46
+ end
47
+
48
+ # Compose two types into an Implication type
49
+ #
50
+ # @param [Type] other
51
+ #
52
+ # @return [Implication, Implication::Constrained]
53
+ #
54
+ # @api private
55
+ def >(other)
56
+ compose(other, Implication)
37
57
  end
38
58
 
39
59
  # Turn a type into an optional type
@@ -76,7 +96,7 @@ module Dry
76
96
  " value every time. Call `.freeze` when setting the default"\
77
97
  " or pass `shared: true` to discard this warning."\
78
98
  "\n#{where}",
79
- tag: :'dry-types'
99
+ tag: :"dry-types"
80
100
  )
81
101
  end
82
102
 
@@ -105,7 +125,7 @@ module Dry
105
125
  if values.length == 1 && values[0].is_a?(::Hash)
106
126
  values[0]
107
127
  else
108
- ::Hash[values.zip(values)]
128
+ values.zip(values).to_h
109
129
  end
110
130
 
111
131
  Enum.new(constrained(included_in: mapping.keys), mapping: mapping)
@@ -147,7 +167,7 @@ module Dry
147
167
  # @return [Constructor]
148
168
  #
149
169
  # @api public
150
- def fallback(value = Undefined, shared: false, &_fallback)
170
+ def fallback(value = Undefined, shared: false, &_fallback) # rubocop:disable Metrics/PerceivedComplexity
151
171
  if Undefined.equal?(value) && !block_given?
152
172
  raise ::ArgumentError, "fallback value or a block must be given"
153
173
  end
@@ -167,7 +187,7 @@ module Dry
167
187
  " value every time. Call `.freeze` when setting the fallback"\
168
188
  " or pass `shared: true` to discard this warning."\
169
189
  "\n#{where}",
170
- tag: :'dry-types'
190
+ tag: :"dry-types"
171
191
  )
172
192
  end
173
193
 
@@ -181,12 +201,21 @@ module Dry
181
201
  end
182
202
  end
183
203
  end
204
+
205
+ private
206
+
207
+ # @api private
208
+ def compose(other, composition_class)
209
+ klass =
210
+ if constrained? && other.constrained?
211
+ composition_class::Constrained
212
+ else
213
+ composition_class
214
+ end
215
+
216
+ klass.new(self, other)
217
+ end
184
218
  end
219
+ # rubocop:enable Metrics/ModuleLength
185
220
  end
186
221
  end
187
-
188
- require "dry/types/default"
189
- require "dry/types/constrained"
190
- require "dry/types/enum"
191
- require "dry/types/lax"
192
- require "dry/types/sum"
@@ -80,7 +80,7 @@ module Dry
80
80
  # @param [#call,nil] block Value constructor
81
81
  #
82
82
  # @return [Dry::Types::Type]
83
- def Constructor(klass, cons = nil, &block)
83
+ def Constructor(klass, cons = nil, &block) # rubocop:disable Metrics/PerceivedComplexity:
84
84
  if klass.is_a?(Type)
85
85
  if cons || block
86
86
  klass.constructor(cons || block)
@@ -12,9 +12,10 @@ module Dry
12
12
  module Params
13
13
  TRUE_VALUES = %w[1 on On ON t true True TRUE T y yes Yes YES Y].freeze
14
14
  FALSE_VALUES = %w[0 off Off OFF f false False FALSE F n no No NO N].freeze
15
- BOOLEAN_MAP = ::Hash[
16
- TRUE_VALUES.product([true]) + FALSE_VALUES.product([false])
17
- ].merge(true => true, false => false).freeze
15
+ BOOLEAN_MAP = EMPTY_HASH.merge(
16
+ [true, *TRUE_VALUES].to_h { |v| [v, true] },
17
+ [false, *FALSE_VALUES].to_h { |v| [v, false] }
18
+ ).freeze
18
19
 
19
20
  extend Coercions
20
21
 
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/core/deprecations"
4
-
5
3
  module Dry
6
4
  module Types
7
5
  # @api private
8
6
  class Compiler
9
- extend ::Dry::Core::Deprecations[:'dry-types']
7
+ extend ::Dry::Core::Deprecations[:"dry-types"]
10
8
 
11
9
  attr_reader :registry
12
10
 
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/core/equalizer"
4
+ require "dry/types/options"
5
+ require "dry/types/meta"
6
+
7
+ module Dry
8
+ module Types
9
+ module Composition
10
+ include Type
11
+ include Builder
12
+ include Options
13
+ include Meta
14
+ include Printable
15
+ include Dry::Equalizer(:left, :right, :options, :meta, inspect: false, immutable: true)
16
+
17
+ # @return [Type]
18
+ attr_reader :left
19
+
20
+ # @return [Type]
21
+ attr_reader :right
22
+
23
+ module Constrained
24
+ def rule
25
+ left.rule.public_send(self.class.operator, right.rule)
26
+ end
27
+
28
+ def constrained?
29
+ true
30
+ end
31
+ end
32
+
33
+ def self.included(base)
34
+ composition_name = Inflector.demodulize(base)
35
+ ast_type = Inflector.underscore(composition_name).to_sym
36
+ base.define_singleton_method(:ast_type) { ast_type }
37
+ base.define_singleton_method(:composition_name) { composition_name }
38
+ base.const_set("Constrained", Class.new(base) { include Constrained })
39
+ end
40
+
41
+ # @param [Type] left
42
+ # @param [Type] right
43
+ # @param [Hash] options
44
+ #
45
+ # @api private
46
+ def initialize(left, right, **options)
47
+ super
48
+ @left, @right = left, right
49
+ freeze
50
+ end
51
+
52
+ # @return [String]
53
+ #
54
+ # @api public
55
+ def name
56
+ [left, right].map(&:name).join(" #{self.class.operator} ")
57
+ end
58
+
59
+ # @return [false]
60
+ #
61
+ # @api public
62
+ def default?
63
+ false
64
+ end
65
+
66
+ # @return [false]
67
+ #
68
+ # @api public
69
+ def constrained?
70
+ false
71
+ end
72
+
73
+ # @return [Boolean]
74
+ #
75
+ # @api public
76
+ def optional?
77
+ false
78
+ end
79
+
80
+ # @param [Object] input
81
+ #
82
+ # @return [Object]
83
+ #
84
+ # @api private
85
+ def call_unsafe(input)
86
+ raise NotImplementedError
87
+ end
88
+
89
+ # @param [Object] input
90
+ #
91
+ # @return [Object]
92
+ #
93
+ # @api private
94
+ def call_safe(input, &block)
95
+ raise NotImplementedError
96
+ end
97
+
98
+ # @param [Object] input
99
+ #
100
+ # @api public
101
+ def try(input)
102
+ raise NotImplementedError
103
+ end
104
+
105
+ # @api private
106
+ def success(input)
107
+ result = try(input)
108
+ if result.success?
109
+ result
110
+ else
111
+ raise ArgumentError, "Invalid success value '#{input}' for #{inspect}"
112
+ end
113
+ end
114
+
115
+ # @api private
116
+ def failure(input, _error = nil)
117
+ result = try(input)
118
+ if result.failure?
119
+ result
120
+ else
121
+ raise ArgumentError, "Invalid failure value '#{input}' for #{inspect}"
122
+ end
123
+ end
124
+
125
+ # @param [Object] value
126
+ #
127
+ # @return [Boolean]
128
+ #
129
+ # @api private
130
+ def primitive?(value)
131
+ raise NotImplementedError
132
+ end
133
+
134
+ # @see Nominal#to_ast
135
+ #
136
+ # @api public
137
+ def to_ast(meta: true)
138
+ [self.class.ast_type,
139
+ [left.to_ast(meta: meta), right.to_ast(meta: meta), meta ? self.meta : EMPTY_HASH]]
140
+ end
141
+
142
+ # Wrap the type with a proc
143
+ #
144
+ # @return [Proc]
145
+ #
146
+ # @api public
147
+ def to_proc
148
+ proc { |value| self.(value) }
149
+ end
150
+ end
151
+ end
152
+ end
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/core/equalizer"
4
- require "dry/types/decorator"
5
- require "dry/types/constraints"
6
- require "dry/types/constrained/coercible"
7
-
8
3
  module Dry
9
4
  module Types
10
5
  # Constrained types apply rules to the input
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/logic/rule_compiler"
4
- require "dry/logic/predicates"
5
- require "dry/logic/rule/predicate"
6
-
7
3
  module Dry
8
4
  # Helper methods for constraint types
9
5
  #
@@ -17,8 +13,8 @@ module Dry
17
13
  def self.Rule(options)
18
14
  rule_compiler.(
19
15
  options.map { |key, val|
20
- Logic::Rule::Predicate.build(
21
- Logic::Predicates[:"#{key}?"]
16
+ ::Dry::Logic::Rule::Predicate.build(
17
+ ::Dry::Logic::Predicates[:"#{key}?"]
22
18
  ).curry(val).to_ast
23
19
  }
24
20
  ).reduce(:and)
@@ -28,7 +24,7 @@ module Dry
28
24
  #
29
25
  # @api private
30
26
  def self.rule_compiler
31
- @rule_compiler ||= Logic::RuleCompiler.new(Logic::Predicates)
27
+ @rule_compiler ||= ::Dry::Logic::RuleCompiler.new(::Dry::Logic::Predicates)
32
28
  end
33
29
  end
34
30
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/core/equalizer"
4
3
  require "concurrent/map"
5
4
 
6
5
  module Dry
@@ -62,17 +61,17 @@ module Dry
62
61
  ::Module.new do
63
62
  if safe
64
63
  module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
65
- def call(input, &block)
66
- @target.#{method}(input, &block)
67
- end
64
+ def call(input, &block) # def call(input, &block)
65
+ @target.#{method}(input, &block) # @target.coerve(input, &block)
66
+ end # end
68
67
  RUBY
69
68
  else
70
69
  module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
71
- def call(input, &block)
72
- @target.#{method}(input)
73
- rescue ::NoMethodError, ::TypeError, ::ArgumentError => error
74
- CoercionError.handle(error, &block)
75
- end
70
+ def call(input, &block) # def call(input, &block)
71
+ @target.#{method}(input) # @target.coerce(input)
72
+ rescue ::NoMethodError, ::TypeError, ::ArgumentError => error # rescue ::NoMethodError, ::TypeError, ::ArgumentError => error
73
+ CoercionError.handle(error, &block) # CoercionError.handle(error, &block)
74
+ end # end
76
75
  RUBY
77
76
  end
78
77
  end
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/core/equalizer"
4
- require "dry/types/fn_container"
5
- require "dry/types/constructor/function"
6
- require "dry/types/constructor/wrapper"
7
-
8
3
  module Dry
9
4
  module Types
10
5
  # Constructor types apply a function to the input that is supposed to return
@@ -27,9 +22,9 @@ module Dry
27
22
  # @param [#call, nil] block
28
23
  #
29
24
  # @api public
30
- def self.new(input, **options, &block)
25
+ def self.new(input, fn: Undefined, **options, &block)
31
26
  type = input.is_a?(Builder) ? input : Nominal.new(input)
32
- super(type, **options, fn: Function[options.fetch(:fn, block)])
27
+ super(type, **options, fn: Function[Undefined.default(fn, block)])
33
28
  end
34
29
 
35
30
  # @param [Builder, Object] input
@@ -49,13 +44,12 @@ module Dry
49
44
 
50
45
  # @api private
51
46
  def self.wrapper_type
52
- @wrapper_type ||= begin
47
+ @wrapper_type ||=
53
48
  if self < Wrapper
54
49
  self
55
50
  else
56
51
  const_set(:Wrapping, ::Class.new(self).include(Wrapper))
57
52
  end
58
- end
59
53
  end
60
54
 
61
55
  # Instantiate a new constructor type instance
@@ -191,7 +185,7 @@ module Dry
191
185
  if type.respond_to?(method)
192
186
  response = type.public_send(method, *args, &block)
193
187
 
194
- if response.is_a?(Type) && type.class.equal?(response.class)
188
+ if response.is_a?(Type) && response.instance_of?(type.class)
195
189
  response.constructor_type[response, **options]
196
190
  else
197
191
  response
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/container"
4
-
5
3
  module Dry
6
4
  module Types
7
5
  # Internal container for the built-in types
8
6
  #
9
7
  # @api private
10
8
  class Container
11
- include Dry::Container::Mixin
9
+ include Core::Container::Mixin
12
10
  end
13
11
  end
14
12
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/types/any"
4
-
5
3
  module Dry
6
4
  module Types
7
5
  # Primitives with {Kernel} coercion methods
@@ -60,7 +58,8 @@ module Dry
60
58
 
61
59
  # Register {KERNEL_COERCIBLE} types
62
60
  KERNEL_COERCIBLE.each do |name, primitive|
63
- register("coercible.#{name}", self["nominal.#{name}"].constructor(Kernel.method(primitive.name)))
61
+ register("coercible.#{name}",
62
+ self["nominal.#{name}"].constructor(Kernel.method(primitive.name)))
64
63
  end
65
64
 
66
65
  # Register {METHOD_COERCIBLE} types