dry-types 1.5.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/LICENSE +1 -1
- data/README.md +5 -4
- data/dry-types.gemspec +18 -18
- data/lib/dry/types/array/constructor.rb +0 -2
- data/lib/dry/types/array/member.rb +1 -3
- data/lib/dry/types/array.rb +0 -3
- data/lib/dry/types/builder.rb +43 -14
- data/lib/dry/types/builder_methods.rb +1 -1
- data/lib/dry/types/coercions/params.rb +4 -3
- data/lib/dry/types/compat.rb +1 -0
- data/lib/dry/types/compiler.rb +1 -3
- data/lib/dry/types/composition.rb +152 -0
- data/lib/dry/types/constrained.rb +0 -5
- data/lib/dry/types/constraints.rb +3 -7
- data/lib/dry/types/constructor/function.rb +8 -9
- data/lib/dry/types/constructor.rb +2 -8
- data/lib/dry/types/container.rb +1 -3
- data/lib/dry/types/core.rb +2 -3
- data/lib/dry/types/decorator.rb +0 -2
- data/lib/dry/types/default.rb +3 -6
- data/lib/dry/types/enum.rb +0 -3
- data/lib/dry/types/errors.rb +13 -1
- data/lib/dry/types/extensions/maybe.rb +8 -5
- data/lib/dry/types/extensions/monads.rb +7 -2
- data/lib/dry/types/fn_container.rb +0 -2
- data/lib/dry/types/hash/constructor.rb +2 -4
- data/lib/dry/types/hash.rb +0 -5
- data/lib/dry/types/implication.rb +66 -0
- data/lib/dry/types/intersection.rb +108 -0
- data/lib/dry/types/lax.rb +1 -4
- data/lib/dry/types/map.rb +9 -3
- data/lib/dry/types/module.rb +18 -9
- data/lib/dry/types/nominal.rb +2 -13
- data/lib/dry/types/predicate_inferrer.rb +3 -9
- data/lib/dry/types/predicate_registry.rb +7 -7
- data/lib/dry/types/primitive_inferrer.rb +0 -2
- data/lib/dry/types/printer/composition.rb +44 -0
- data/lib/dry/types/printer.rb +116 -131
- data/lib/dry/types/result.rb +0 -2
- data/lib/dry/types/schema/key.rb +1 -4
- data/lib/dry/types/schema.rb +6 -4
- data/lib/dry/types/sum.rb +3 -95
- data/lib/dry/types/type.rb +1 -3
- data/lib/dry/types/version.rb +1 -1
- data/lib/dry/types.rb +48 -21
- metadata +37 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdd7e08f86f3137ead67bb6170e91de625227e97783be335b982e5a4c313b32e
|
4
|
+
data.tar.gz: faa51ae68eb4942cb64520eed7d6c4dbf5b46af384a91acdfc94105f32298839
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 588feadceca555b168266b6e6ee542d71b154152ea56a88f7b601c33a79b116c90b86356e03bc8ca273e4df5d38e4056277c88502387e836bba4af8409fede14
|
7
|
+
data.tar.gz: 72326eb3f32d33cbc95d1e20d6bec4f1bc40a66fa6cac818d35b8ff2214d3932f3350d5e6cf36a6a49ea3ffd862d7422a49622d5a98937a0be6f914d0f390965
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.7.0 2022-11-04
|
4
|
+
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
|
8
|
+
- This version is compatible with recently released dry-rb dependencies (@flash-gordon)
|
9
|
+
- Updated to dry-core 1.0 (@flash-gordon + @solnic)
|
10
|
+
- Dependency on dry-container was dropped (@flash-gordon)
|
11
|
+
|
12
|
+
[Compare v1.6.1...v1.7.0](https://github.com/dry-rb/dry-types/compare/v1.6.1...v1.7.0)
|
13
|
+
|
14
|
+
## 1.6.1 2022-10-15
|
15
|
+
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- Fix issues with internal const_missing and Inflector/Module constants (@flash-gordon + @solnic)
|
20
|
+
|
21
|
+
[Compare v1.6.0...v1.6.1](https://github.com/dry-rb/dry-types/compare/v1.6.0...v1.6.1)
|
22
|
+
|
23
|
+
## 1.6.0 2022-10-15
|
24
|
+
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
|
28
|
+
- Optimize `PredicateRegistry` for Ruby 2.7+ (see #420 for more details) (@casperisfine)
|
29
|
+
- Use zeitwerk for auto-loading (@flash-gordon)
|
30
|
+
|
31
|
+
[Compare v1.5.1...v1.6.0](https://github.com/dry-rb/dry-types/compare/v1.5.1...v1.6.0)
|
32
|
+
|
3
33
|
## 1.5.1 2021-02-16
|
4
34
|
|
5
35
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
<!--- this file is synced from dry-rb/template-gem project -->
|
1
2
|
[gem]: https://rubygems.org/gems/dry-types
|
2
3
|
[actions]: https://github.com/dry-rb/dry-types/actions
|
3
4
|
[codacy]: https://www.codacy.com/gh/dry-rb/dry-types
|
@@ -10,19 +11,19 @@
|
|
10
11
|
[![CI Status](https://github.com/dry-rb/dry-types/workflows/ci/badge.svg)][actions]
|
11
12
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f2d71613195f4da993acb9ac9d6ea336)][codacy]
|
12
13
|
[![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=
|
14
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-types.svg?branch=main)][inchpages]
|
14
15
|
|
15
16
|
## Links
|
16
17
|
|
17
|
-
* [User documentation](
|
18
|
+
* [User documentation](https://dry-rb.org/gems/dry-types)
|
18
19
|
* [API documentation](http://rubydoc.info/gems/dry-types)
|
19
20
|
|
20
21
|
## Supported Ruby versions
|
21
22
|
|
22
23
|
This library officially supports the following Ruby versions:
|
23
24
|
|
24
|
-
* MRI
|
25
|
-
* jruby
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
26
27
|
|
27
28
|
## License
|
28
29
|
|
data/dry-types.gemspec
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# this file is managed by dry-rb/devtools project
|
3
2
|
|
4
|
-
|
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
|
7
|
+
require "dry/types/version"
|
7
8
|
|
8
9
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name =
|
10
|
+
spec.name = "dry-types"
|
10
11
|
spec.authors = ["Piotr Solnica"]
|
11
12
|
spec.email = ["piotr.solnica@gmail.com"]
|
12
|
-
spec.license =
|
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 =
|
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 =
|
20
|
+
spec.bindir = "bin"
|
20
21
|
spec.executables = []
|
21
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ["lib"]
|
22
23
|
|
23
|
-
spec.metadata[
|
24
|
-
spec.metadata[
|
25
|
-
spec.metadata[
|
26
|
-
spec.metadata[
|
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.
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
29
30
|
|
30
31
|
# to update dependencies edit project.yml
|
31
32
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
32
|
-
spec.add_runtime_dependency "dry-
|
33
|
-
spec.add_runtime_dependency "dry-
|
34
|
-
spec.add_runtime_dependency "dry-
|
35
|
-
spec.add_runtime_dependency "
|
33
|
+
spec.add_runtime_dependency "dry-core", "~> 1.0", "< 2"
|
34
|
+
spec.add_runtime_dependency "dry-inflector", "~> 1.0", "< 2"
|
35
|
+
spec.add_runtime_dependency "dry-logic", ">= 1.4", "< 2"
|
36
|
+
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
|
36
37
|
|
37
38
|
spec.add_development_dependency "bundler"
|
38
|
-
spec.add_development_dependency "dry-monads", "~> 1.0"
|
39
39
|
spec.add_development_dependency "rake"
|
40
40
|
spec.add_development_dependency "rspec"
|
41
41
|
spec.add_development_dependency "yard"
|
@@ -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
|
|
data/lib/dry/types/array.rb
CHANGED
data/lib/dry/types/builder.rb
CHANGED
@@ -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
|
-
|
36
|
-
|
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: :
|
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
|
-
|
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: :
|
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 =
|
16
|
-
|
17
|
-
|
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
|
|
data/lib/dry/types/compat.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
# frozen_string_literal: true
|
data/lib/dry/types/compiler.rb
CHANGED
@@ -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[:
|
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,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
|
@@ -49,13 +44,12 @@ module Dry
|
|
49
44
|
|
50
45
|
# @api private
|
51
46
|
def self.wrapper_type
|
52
|
-
@wrapper_type ||=
|
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) &&
|
188
|
+
if response.is_a?(Type) && response.instance_of?(type.class)
|
195
189
|
response.constructor_type[response, **options]
|
196
190
|
else
|
197
191
|
response
|
data/lib/dry/types/container.rb
CHANGED
@@ -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
|
9
|
+
include Core::Container::Mixin
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
data/lib/dry/types/core.rb
CHANGED
@@ -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}",
|
61
|
+
register("coercible.#{name}",
|
62
|
+
self["nominal.#{name}"].constructor(Kernel.method(primitive.name)))
|
64
63
|
end
|
65
64
|
|
66
65
|
# Register {METHOD_COERCIBLE} types
|
data/lib/dry/types/decorator.rb
CHANGED
data/lib/dry/types/default.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dry/core/equalizer"
|
4
|
-
require "dry/types/decorator"
|
5
|
-
|
6
3
|
module Dry
|
7
4
|
module Types
|
8
5
|
# Default types are useful when a missing value should be replaced by a default one
|
@@ -53,7 +50,7 @@ module Dry
|
|
53
50
|
# @param [Object] value
|
54
51
|
#
|
55
52
|
# @api private
|
56
|
-
def initialize(type, value, **
|
53
|
+
def initialize(type, value, **)
|
57
54
|
super
|
58
55
|
@value = value
|
59
56
|
end
|
@@ -65,8 +62,8 @@ module Dry
|
|
65
62
|
# @return [Default]
|
66
63
|
#
|
67
64
|
# @api public
|
68
|
-
def constrained(
|
69
|
-
type.constrained(
|
65
|
+
def constrained(...)
|
66
|
+
type.constrained(...).default(value)
|
70
67
|
end
|
71
68
|
|
72
69
|
# @return [true]
|