dry-logic 1.5.0 → 1.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +166 -165
- data/LICENSE +1 -1
- data/README.md +13 -13
- data/dry-logic.gemspec +12 -10
- data/lib/dry/logic/builder.rb +8 -8
- data/lib/dry/logic/operations/abstract.rb +1 -1
- data/lib/dry/logic/operations/check.rb +1 -1
- data/lib/dry/logic/operations/each.rb +1 -1
- data/lib/dry/logic/predicates.rb +77 -138
- data/lib/dry/logic/result.rb +1 -1
- data/lib/dry/logic/rule/interface.rb +16 -22
- data/lib/dry/logic/rule.rb +2 -2
- data/lib/dry/logic/version.rb +1 -1
- metadata +28 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92f4229d57362a22f58cce16cf8b0f14199367c38d22941b83c0be0570b3369a
|
|
4
|
+
data.tar.gz: adfc35267a0567f76dc63d8f0a8909de82421a3d1d51d0c4f7a9cc21ef228cc4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05b5f61f82fbac6bd701dafb2f3f13730223801764041fbb0a1deb8b9f73bb8517cc24cbf7bb234d2179fb766a3c02799b6384b41efcc2ff4d4bc03af48f8f82
|
|
7
|
+
data.tar.gz: e5bbc3b729c76d9dfcc4324c21c99c993d4c7aa4563b21314d928cadc2b4bf777fd3605abd64771d9b7f5576a845457254b4bbc69eb02db3adeea0711e6f7bc9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,362 +1,363 @@
|
|
|
1
|
-
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
## [Unreleased]
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
### Added
|
|
9
10
|
|
|
10
11
|
### Changed
|
|
11
12
|
|
|
12
|
-
-
|
|
13
|
-
- Made `Predicates.eql?` compatible with `Object#eql?` (via #106) (@solnic)
|
|
13
|
+
- Set minimum Ruby version to 3.3.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
### Deprecated
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
### Removed
|
|
18
18
|
|
|
19
|
+
### Fixed
|
|
19
20
|
|
|
20
|
-
###
|
|
21
|
+
### Security
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
[Unreleased]: https://github.com/dry-rb/dry-logic/compare/v1.6.1...main
|
|
23
24
|
|
|
24
|
-
[
|
|
25
|
+
## [1.6.1] - 2026-11-24
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
### Security
|
|
27
28
|
|
|
29
|
+
- Make the `uri?` predicate match only when the whole input is a URI with a permitted scheme. Previously it matched any input that contained one, such as `javascript:alert(1)//https://example.com`. (@parndt in GHSA-88x6-8wr7-j6gp)
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
[1.6.1]: https://github.com/dry-rb/dry-logic/compare/v1.6.0...v1.6.1
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
## [1.6.0] - 2025-01-04
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
### Added
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
- Support for more UUID formats. (@Ptico in #110)
|
|
36
38
|
|
|
39
|
+
### Changed
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
- Set 3.1 as minimum ruby version. (@flash-gordon)
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
### Fixed
|
|
41
44
|
|
|
45
|
+
- Fix NoMethodError when trying to get AST of a Builder's result. (@estum in #107)
|
|
42
46
|
|
|
43
|
-
[
|
|
47
|
+
[1.6.0]: https://github.com/dry-rb/dry-logic/compare/v1.5.0...v1.6.0
|
|
44
48
|
|
|
45
|
-
## 1.
|
|
49
|
+
## [1.5.0] - 2022-11-24
|
|
46
50
|
|
|
51
|
+
### Added
|
|
47
52
|
|
|
48
|
-
|
|
53
|
+
- `uri_rfc3986?` predicate that uses a better regexp than `uri?`. (@hieuk09 in #94)
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
### Changed
|
|
51
56
|
|
|
57
|
+
- Made `Predicates.respond_to?` compatible with `Object#respond_to?`. (@solnic in #105)
|
|
58
|
+
- Made `Predicates.eql?` compatible with `Object#eql?`. (@solnic in #106)
|
|
52
59
|
|
|
53
|
-
[
|
|
60
|
+
[1.5.0]: https://github.com/dry-rb/dry-logic/compare/v1.4.0...v1.5.0
|
|
54
61
|
|
|
55
|
-
## 1.
|
|
62
|
+
## [1.4.0] - 2022-11-04
|
|
56
63
|
|
|
64
|
+
### Changed
|
|
57
65
|
|
|
58
|
-
|
|
66
|
+
- Updated to dry-core 1.0. (@flash-gordon and @solnic)
|
|
59
67
|
|
|
60
|
-
-
|
|
68
|
+
[1.4.0]: https://github.com/dry-rb/dry-logic/compare/v1.3.0...v1.4.0
|
|
69
|
+
|
|
70
|
+
## [1.3.0] - 2022-10-15
|
|
61
71
|
|
|
62
72
|
### Changed
|
|
63
73
|
|
|
64
|
-
-
|
|
74
|
+
- Use zeitwerk for auto-loading. (@solnic and @flash-gordon)
|
|
65
75
|
|
|
66
|
-
[
|
|
76
|
+
[1.3.0]: https://github.com/dry-rb/dry-logic/compare/v1.2.0...v1.3.0
|
|
67
77
|
|
|
68
|
-
## 1.0
|
|
78
|
+
## [1.2.0] - 2021-04-26
|
|
69
79
|
|
|
80
|
+
### Added
|
|
70
81
|
|
|
71
|
-
|
|
82
|
+
- Add predicate and operation builder DSL. (@oleander)
|
|
72
83
|
|
|
73
|
-
|
|
84
|
+
[1.2.0]: https://github.com/dry-rb/dry-logic/compare/v1.1.1...v1.2.0
|
|
74
85
|
|
|
86
|
+
## [1.1.1] - 2021-04-14
|
|
75
87
|
|
|
76
|
-
|
|
88
|
+
### Fixed
|
|
77
89
|
|
|
78
|
-
|
|
90
|
+
- Fixed a crash under jruby caused by arg splatting in Binary operations. (@flash-gordon)
|
|
79
91
|
|
|
92
|
+
[1.1.1]: https://github.com/dry-rb/dry-logic/compare/v1.1.0...v1.1.1
|
|
80
93
|
|
|
81
|
-
|
|
94
|
+
## [1.1.0] - 2020-12-26
|
|
95
|
+
|
|
96
|
+
### Changed
|
|
82
97
|
|
|
83
|
-
-
|
|
84
|
-
- New predicates: `uuid_v1?`, `uuid_v2?`, `uuid_v3?` and `uuid_v5?` (via #75) (@jamesbrauman)
|
|
98
|
+
- Switched to equalizer from dry-core. (@solnic)
|
|
85
99
|
|
|
100
|
+
### Fixed
|
|
86
101
|
|
|
87
|
-
|
|
102
|
+
- Nested `Check` operations no longer crash under MRI 3.0. (@oleander)
|
|
88
103
|
|
|
89
|
-
|
|
104
|
+
[1.1.0]: https://github.com/dry-rb/dry-logic/compare/v1.0.8...v1.1.0
|
|
90
105
|
|
|
106
|
+
## [1.0.8] - 2020-09-28
|
|
91
107
|
|
|
92
108
|
### Fixed
|
|
93
109
|
|
|
94
|
-
-
|
|
110
|
+
- Better Ruby 3 support with fixed specialization for rules of negative arity. (@flash-gordon)
|
|
95
111
|
|
|
112
|
+
[1.0.8]: https://github.com/dry-rb/dry-logic/compare/v1.0.7...v1.0.8
|
|
96
113
|
|
|
97
|
-
[
|
|
114
|
+
## [1.0.7] - 2020-08-13
|
|
98
115
|
|
|
99
|
-
|
|
116
|
+
### Added
|
|
100
117
|
|
|
118
|
+
- A new `uri?` predicate that you can use to verify `URI` strings, ie `uri?("https", "https://dry-rb.org")`. (@nerburish)
|
|
119
|
+
- New predicates: `uuid_v1?`, `uuid_v2?`, `uuid_v3?` and `uuid_v5?`. (@jamesbrauman in #75)
|
|
101
120
|
|
|
102
|
-
|
|
121
|
+
[1.0.7]: https://github.com/dry-rb/dry-logic/compare/v1.0.6...v1.0.7
|
|
103
122
|
|
|
104
|
-
|
|
123
|
+
## [1.0.6] - 2020-02-10
|
|
105
124
|
|
|
125
|
+
### Fixed
|
|
106
126
|
|
|
107
|
-
|
|
127
|
+
- Made the regexp used by `uuid_v4?` more secure. (@kml)
|
|
108
128
|
|
|
109
|
-
|
|
129
|
+
[1.0.6]: https://github.com/dry-rb/dry-logic/compare/v1.0.5...v1.0.6
|
|
110
130
|
|
|
131
|
+
## [1.0.5] - 2019-11-07
|
|
111
132
|
|
|
112
133
|
### Fixed
|
|
113
134
|
|
|
114
|
-
-
|
|
135
|
+
- Make `format?` tolerant to `nil` values. It already worked like that before, but starting Ruby 2.7 it would produce warnings. Now it won't. Don't rely on this behavior, it's only added to make tests pass in dry-schema. Use explicit type checks instead. (@flash-gordon)
|
|
115
136
|
|
|
137
|
+
[1.0.5]: https://github.com/dry-rb/dry-logic/compare/v1.0.4...v1.0.5
|
|
138
|
+
|
|
139
|
+
## [1.0.4] - 2019-11-06
|
|
140
|
+
|
|
141
|
+
### Fixed
|
|
116
142
|
|
|
117
|
-
|
|
143
|
+
- Fix keyword warnings. (@flash-gordon)
|
|
118
144
|
|
|
119
|
-
|
|
145
|
+
[1.0.4]: https://github.com/dry-rb/dry-logic/compare/v1.0.3...v1.0.4
|
|
120
146
|
|
|
147
|
+
## [1.0.3] - 2019-08-01
|
|
121
148
|
|
|
122
149
|
### Added
|
|
123
150
|
|
|
124
|
-
- `bytesize?` predicate (@bmalinconico)
|
|
125
|
-
- `min_bytesize?` predicate (@bmalinconico)
|
|
126
|
-
- `max_bytesize
|
|
151
|
+
- `bytesize?` predicate. (@bmalinconico)
|
|
152
|
+
- `min_bytesize?` predicate. (@bmalinconico)
|
|
153
|
+
- `max_bytesize?` predicate. (@bmalinconico)
|
|
127
154
|
|
|
128
155
|
### Changed
|
|
129
156
|
|
|
130
|
-
- Min ruby version was set to `>= 2.4.0
|
|
157
|
+
- Min ruby version was set to `>= 2.4.0`. (@flash-gordon)
|
|
131
158
|
|
|
132
|
-
[
|
|
159
|
+
[1.0.3]: https://github.com/dry-rb/dry-logic/compare/v1.0.2...v1.0.3
|
|
133
160
|
|
|
134
|
-
## 1.0.2 2019-06-14
|
|
161
|
+
## [1.0.2] - 2019-06-14
|
|
135
162
|
|
|
136
163
|
Re-pushed 1.0.1 after dry-schema 1.2.0 release.
|
|
137
164
|
|
|
165
|
+
[1.0.2]: https://github.com/dry-rb/dry-logic/compare/v1.0.1...v1.0.2
|
|
138
166
|
|
|
139
|
-
[
|
|
140
|
-
|
|
141
|
-
## 1.0.1 2019-06-04
|
|
167
|
+
## [1.0.1] - 2019-06-04
|
|
142
168
|
|
|
143
169
|
This release was removed from rubygems because it broke dry-schema.
|
|
144
170
|
|
|
145
171
|
### Added
|
|
146
172
|
|
|
147
|
-
- `uuid_v4?` predicate (radar)
|
|
148
|
-
- `respond_to?` predicate (waiting-for-dev)
|
|
149
|
-
|
|
173
|
+
- `uuid_v4?` predicate. (@radar)
|
|
174
|
+
- `respond_to?` predicate. (@waiting-for-dev)
|
|
150
175
|
|
|
151
|
-
[
|
|
152
|
-
|
|
153
|
-
## 1.0.0 2019-04-23
|
|
176
|
+
[1.0.1]: https://github.com/dry-rb/dry-logic/compare/v1.0.0...v1.0.1
|
|
154
177
|
|
|
178
|
+
## [1.0.0] - 2019-04-23
|
|
155
179
|
|
|
156
180
|
### Changed
|
|
157
181
|
|
|
158
|
-
- Version bump to `1.0.0
|
|
159
|
-
|
|
160
|
-
[Compare v0.6.1...v1.0.0](https://github.com/dry-rb/dry-logic/compare/v0.6.1...v1.0.0)
|
|
182
|
+
- Version bump to `1.0.0`. (@flash-gordon)
|
|
161
183
|
|
|
162
|
-
|
|
184
|
+
[1.0.0]: https://github.com/dry-rb/dry-logic/compare/v0.6.1...v1.0.0
|
|
163
185
|
|
|
186
|
+
## [0.6.1] - 2019-04-18
|
|
164
187
|
|
|
165
188
|
### Fixed
|
|
166
189
|
|
|
167
|
-
- Fix a regression in dry-validation 0.x for argument-less predicates (flash-gordon)
|
|
190
|
+
- Fix a regression in dry-validation 0.x for argument-less predicates. (@flash-gordon)
|
|
168
191
|
|
|
192
|
+
[0.6.1]: https://github.com/dry-rb/dry-logic/compare/v0.6.0...v0.6.1
|
|
169
193
|
|
|
170
|
-
[
|
|
171
|
-
|
|
172
|
-
## 0.6.0 2019-04-04
|
|
173
|
-
|
|
194
|
+
## [0.6.0] - 2019-04-04
|
|
174
195
|
|
|
175
196
|
### Added
|
|
176
197
|
|
|
177
|
-
- Generating hints can be disabled by building `Operations::And` with `hints: false` option set (solnic)
|
|
198
|
+
- Generating hints can be disabled by building `Operations::And` with `hints: false` option set. (@solnic)
|
|
178
199
|
|
|
179
200
|
### Changed
|
|
180
201
|
|
|
181
|
-
- `Rule` construction has been optimized so that currying and application is multiple-times faster (flash-gordon)
|
|
182
|
-
|
|
183
|
-
[Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-logic/compare/v0.5.0...v0.6.0)
|
|
202
|
+
- `Rule` construction has been optimized so that currying and application is multiple-times faster. (@flash-gordon)
|
|
184
203
|
|
|
185
|
-
|
|
204
|
+
[0.6.0]: https://github.com/dry-rb/dry-logic/compare/v0.5.0...v0.6.0
|
|
186
205
|
|
|
206
|
+
## [0.5.0] - 2019-01-29
|
|
187
207
|
|
|
188
208
|
### Added
|
|
189
209
|
|
|
190
|
-
- `:nil?` predicate (`none?` is now an alias) (solnic)
|
|
210
|
+
- `:nil?` predicate (`none?` is now an alias). (@solnic)
|
|
191
211
|
|
|
192
212
|
### Fixed
|
|
193
213
|
|
|
194
|
-
- `Operation::Key#ast` will now return a correct AST with non-Undefined inputs (solnic)
|
|
214
|
+
- `Operation::Key#ast` will now return a correct AST with non-Undefined inputs. (@solnic)
|
|
195
215
|
|
|
216
|
+
[0.5.0]: https://github.com/dry-rb/dry-logic/compare/v0.4.2...v0.5.0
|
|
196
217
|
|
|
197
|
-
[
|
|
198
|
-
|
|
199
|
-
## 0.4.2 2017-09-15
|
|
200
|
-
|
|
218
|
+
## [0.4.2] - 2017-09-15
|
|
201
219
|
|
|
202
220
|
### Added
|
|
203
221
|
|
|
204
|
-
- New `:case?` predicate matches a value against the given object with
|
|
205
|
-
- New `:is?` predicate checks objects identity (using `#equal?`) (flash-gordon)
|
|
222
|
+
- New `:case?` predicate matches a value against the given object with `#===`. (@flash-gordon)
|
|
223
|
+
- New `:is?` predicate checks objects identity (using `#equal?`). (@flash-gordon)
|
|
206
224
|
|
|
207
225
|
### Fixed
|
|
208
226
|
|
|
209
|
-
- A bug with using custom predicates within a standalone module in `dry-validation
|
|
227
|
+
- A bug with using custom predicates within a standalone module in `dry-validation`. (@flash-gordon)
|
|
210
228
|
|
|
229
|
+
[0.4.2]: https://github.com/dry-rb/dry-logic/compare/v0.4.1...v0.4.2
|
|
211
230
|
|
|
212
|
-
[
|
|
231
|
+
## [0.4.1] - 2017-01-23
|
|
213
232
|
|
|
214
|
-
|
|
233
|
+
### Changed
|
|
215
234
|
|
|
235
|
+
- Predicates simply reuse other predicate methods instead of referring to them via `#[]`. (@georgemillo)
|
|
216
236
|
|
|
217
237
|
### Fixed
|
|
218
238
|
|
|
219
|
-
- Warnings on MRI 2.4.0 are gone (jtippett)
|
|
239
|
+
- Warnings on MRI 2.4.0 are gone. (@jtippett)
|
|
220
240
|
|
|
221
|
-
|
|
241
|
+
[0.4.1]: https://github.com/dry-rb/dry-logic/compare/v0.4.0...v0.4.1
|
|
222
242
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
[Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-logic/compare/v0.4.0...v0.4.1)
|
|
226
|
-
|
|
227
|
-
## 0.4.0 2016-09-21
|
|
243
|
+
## [0.4.0] - 2016-09-21
|
|
228
244
|
|
|
229
245
|
This is a partial rewrite focused on internal clean up and major performance improvements. This is also the beginning of the work to make this library first-class rather than "just" a rule backend for dry-validation and dry-types.
|
|
230
246
|
|
|
231
247
|
### Added
|
|
232
248
|
|
|
233
|
-
- `Rule#[]` which applies a rule and always returns `true` or `false
|
|
234
|
-
- `Rule#bind` which returns a rule with its predicate bound to a given object (solnic)
|
|
235
|
-
- `Rule#eval_args` which evaluates unbound-methods-args in the context of a given object (solnic)
|
|
236
|
-
- `Logic.Rule` builder function (solnic)
|
|
237
|
-
- Nice `#inspect` on rules and operation objects (solnic)
|
|
249
|
+
- `Rule#[]` which applies a rule and always returns `true` or `false`. (@solnic)
|
|
250
|
+
- `Rule#bind` which returns a rule with its predicate bound to a given object. (@solnic)
|
|
251
|
+
- `Rule#eval_args` which evaluates unbound-methods-args in the context of a given object. (@solnic)
|
|
252
|
+
- `Logic.Rule` builder function. (@solnic)
|
|
253
|
+
- Nice `#inspect` on rules and operation objects. (@solnic)
|
|
238
254
|
|
|
239
255
|
### Changed
|
|
240
256
|
|
|
241
|
-
- [
|
|
242
|
-
- [BREAKING] `Predicate` is now `Rule::Predicate
|
|
243
|
-
- [BREAKING] `Rule::Conjunction` is now `Operation::And
|
|
244
|
-
- [BREAKING] `Rule::Disjunction` is now `Operation::Or
|
|
245
|
-
- [BREAKING] `Rule::ExlusiveDisjunction` is now `Operation::Xor
|
|
246
|
-
- [BREAKING] `Rule::Implication` is now `Operation::Implication
|
|
247
|
-
- [BREAKING] `Rule::Set` is now `Operation::Set
|
|
248
|
-
- [BREAKING] `Rule::Each` is now `Operation::Each
|
|
249
|
-
- [BREAKING] `Rule.new` accepts a predicate function as its first arg now (solnic)
|
|
250
|
-
- [BREAKING] `Rule#name` is now `Rule#id
|
|
251
|
-
- `Rule#parameters` is public now (solnic)
|
|
252
|
-
|
|
253
|
-
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-logic/compare/v0.3.0...v0.4.0)
|
|
257
|
+
- [BREAKING] New result API. (@solnic)
|
|
258
|
+
- [BREAKING] `Predicate` is now `Rule::Predicate`. (@solnic)
|
|
259
|
+
- [BREAKING] `Rule::Conjunction` is now `Operation::And`. (@solnic)
|
|
260
|
+
- [BREAKING] `Rule::Disjunction` is now `Operation::Or`. (@solnic)
|
|
261
|
+
- [BREAKING] `Rule::ExlusiveDisjunction` is now `Operation::Xor`. (@solnic)
|
|
262
|
+
- [BREAKING] `Rule::Implication` is now `Operation::Implication`. (@solnic)
|
|
263
|
+
- [BREAKING] `Rule::Set` is now `Operation::Set`. (@solnic)
|
|
264
|
+
- [BREAKING] `Rule::Each` is now `Operation::Each`. (@solnic)
|
|
265
|
+
- [BREAKING] `Rule.new` accepts a predicate function as its first arg now. (@solnic)
|
|
266
|
+
- [BREAKING] `Rule#name` is now `Rule#id`. (@solnic)
|
|
267
|
+
- `Rule#parameters` is public now. (@solnic)
|
|
254
268
|
|
|
255
|
-
|
|
269
|
+
[0.4.0]: https://github.com/dry-rb/dry-logic/compare/v0.3.0...v0.4.0
|
|
256
270
|
|
|
271
|
+
## [0.3.0] - 2016-07-01
|
|
257
272
|
|
|
258
273
|
### Added
|
|
259
274
|
|
|
260
|
-
- `:type?` predicate imported from dry-types (solnic)
|
|
261
|
-
- `Rule#curry` interface (solnic)
|
|
275
|
+
- `:type?` predicate imported from dry-types. (@solnic)
|
|
276
|
+
- `Rule#curry` interface. (@solnic)
|
|
262
277
|
|
|
263
278
|
### Changed
|
|
264
279
|
|
|
265
|
-
- Predicates AST now includes information about args (names & possible values) (fran-worley
|
|
266
|
-
- Predicates raise errors when they are called with invalid arity (fran-worley
|
|
267
|
-
- Rules no longer evaluate input twice when building result objects (solnic)
|
|
280
|
+
- Predicates AST now includes information about args (names & possible values). (@fran-worley and @solnic)
|
|
281
|
+
- Predicates raise errors when they are called with invalid arity. (@fran-worley and @solnic)
|
|
282
|
+
- Rules no longer evaluate input twice when building result objects. (@solnic)
|
|
268
283
|
|
|
269
|
-
[
|
|
270
|
-
|
|
271
|
-
## 0.2.3 2016-05-11
|
|
284
|
+
[0.3.0]: https://github.com/dry-rb/dry-logic/compare/v0.2.3...v0.3.0
|
|
272
285
|
|
|
286
|
+
## [0.2.3] - 2016-05-11
|
|
273
287
|
|
|
274
288
|
### Added
|
|
275
289
|
|
|
276
|
-
- `not_eql?`, `includes?`, `excludes?` predicates (fran-worley)
|
|
290
|
+
- `not_eql?`, `includes?`, `excludes?` predicates. (@fran-worley)
|
|
277
291
|
|
|
278
292
|
### Changed
|
|
279
293
|
|
|
280
|
-
- Renamed `inclusion?` to `included_in?` and deprecated `inclusion
|
|
281
|
-
- Renamed `exclusion?` to `excluded_from?` and deprecated `exclusion
|
|
282
|
-
|
|
283
|
-
[Compare v0.2.2...v0.2.3](https://github.com/dry-rb/dry-logic/compare/v0.2.2...v0.2.3)
|
|
294
|
+
- Renamed `inclusion?` to `included_in?` and deprecated `inclusion?`. (@fran-worley)
|
|
295
|
+
- Renamed `exclusion?` to `excluded_from?` and deprecated `exclusion?`. (@fran-worley)
|
|
284
296
|
|
|
285
|
-
|
|
297
|
+
[0.2.3]: https://github.com/dry-rb/dry-logic/compare/v0.2.2...v0.2.3
|
|
286
298
|
|
|
299
|
+
## [0.2.2] - 2016-03-30
|
|
287
300
|
|
|
288
301
|
### Added
|
|
289
302
|
|
|
290
|
-
- `number?`, `odd?`, `even?` predicates (fran-worley)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
[Compare v0.2.1...v0.2.2](https://github.com/dry-rb/dry-logic/compare/v0.2.1...v0.2.2)
|
|
303
|
+
- `number?`, `odd?`, `even?` predicates. (@fran-worley)
|
|
294
304
|
|
|
295
|
-
|
|
305
|
+
[0.2.2]: https://github.com/dry-rb/dry-logic/compare/v0.2.1...v0.2.2
|
|
296
306
|
|
|
307
|
+
## [0.2.1] - 2016-03-20
|
|
297
308
|
|
|
298
309
|
### Fixed
|
|
299
310
|
|
|
300
|
-
- Result AST for `Rule::Each` correctly maps elements with eql inputs (solnic)
|
|
311
|
+
- Result AST for `Rule::Each` correctly maps elements with eql inputs. (@solnic)
|
|
301
312
|
|
|
313
|
+
[0.2.1]: https://github.com/dry-rb/dry-logic/compare/v0.2.0...v0.2.1
|
|
302
314
|
|
|
303
|
-
[
|
|
304
|
-
|
|
305
|
-
## 0.2.0 2016-03-11
|
|
306
|
-
|
|
315
|
+
## [0.2.0] - 2016-03-11
|
|
307
316
|
|
|
308
317
|
### Changed
|
|
309
318
|
|
|
310
|
-
- Entire AST has been redefined (solnic)
|
|
311
|
-
|
|
312
|
-
[Compare v0.1.4...v0.2.0](https://github.com/dry-rb/dry-logic/compare/v0.1.4...v0.2.0)
|
|
319
|
+
- Entire AST has been redefined. (@solnic)
|
|
313
320
|
|
|
314
|
-
|
|
321
|
+
[0.2.0]: https://github.com/dry-rb/dry-logic/compare/v0.1.4...v0.2.0
|
|
315
322
|
|
|
323
|
+
## [0.1.4] - 2016-01-27
|
|
316
324
|
|
|
317
325
|
### Added
|
|
318
326
|
|
|
319
|
-
- Support for hash-names in `Check` and `Result` which can properly resolve input
|
|
320
|
-
from nested results (solnic)
|
|
327
|
+
- Support for hash-names in `Check` and `Result` which can properly resolve input from nested results. (@solnic)
|
|
321
328
|
|
|
329
|
+
[0.1.4]: https://github.com/dry-rb/dry-logic/compare/v0.1.3...v0.1.4
|
|
322
330
|
|
|
323
|
-
[
|
|
324
|
-
|
|
325
|
-
## 0.1.3 2016-01-27
|
|
326
|
-
|
|
331
|
+
## [0.1.3] - 2016-01-27
|
|
327
332
|
|
|
328
333
|
### Added
|
|
329
334
|
|
|
330
|
-
- Support for resolving input from `Rule::Result
|
|
335
|
+
- Support for resolving input from `Rule::Result`. (@solnic)
|
|
331
336
|
|
|
332
337
|
### Changed
|
|
333
338
|
|
|
334
|
-
- `Check` and `Result` carry original input(s) (solnic)
|
|
335
|
-
|
|
336
|
-
[Compare v0.1.2...v0.1.3](https://github.com/dry-rb/dry-logic/compare/v0.1.2...v0.1.3)
|
|
339
|
+
- `Check` and `Result` carry original input(s). (@solnic)
|
|
337
340
|
|
|
338
|
-
|
|
341
|
+
[0.1.3]: https://github.com/dry-rb/dry-logic/compare/v0.1.2...v0.1.3
|
|
339
342
|
|
|
343
|
+
## [0.1.2] - 2016-01-19
|
|
340
344
|
|
|
341
345
|
### Fixed
|
|
342
346
|
|
|
343
|
-
- `xor` returns wrapped results when used against another result-rule (solnic)
|
|
347
|
+
- `xor` returns wrapped results when used against another result-rule. (@solnic)
|
|
344
348
|
|
|
349
|
+
[0.1.2]: https://github.com/dry-rb/dry-logic/compare/v0.1.1...v0.1.2
|
|
345
350
|
|
|
346
|
-
[
|
|
347
|
-
|
|
348
|
-
## 0.1.1 2016-01-18
|
|
349
|
-
|
|
351
|
+
## [0.1.1] - 2016-01-18
|
|
350
352
|
|
|
351
353
|
### Added
|
|
352
354
|
|
|
353
|
-
- `Rule::Attr` which can be applied to a data object with attr readers (SunnyMagadan)
|
|
354
|
-
- `Rule::Result` which can be applied to a result object (solnic)
|
|
355
|
-
- `true?` and `false?` predicates (solnic)
|
|
356
|
-
|
|
355
|
+
- `Rule::Attr` which can be applied to a data object with attr readers. (@SunnyMagadan)
|
|
356
|
+
- `Rule::Result` which can be applied to a result object. (@solnic)
|
|
357
|
+
- `true?` and `false?` predicates. (@solnic)
|
|
357
358
|
|
|
358
|
-
[
|
|
359
|
+
[0.1.1]: https://github.com/dry-rb/dry-logic/compare/v0.1.0...v0.1.1
|
|
359
360
|
|
|
360
|
-
## 0.1.0 2016-01-11
|
|
361
|
+
## 0.1.0 - 2016-01-11
|
|
361
362
|
|
|
362
|
-
Code extracted from dry-validation 0.4.1
|
|
363
|
+
Code extracted from dry-validation 0.4.1.
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<!---
|
|
2
|
-
[gem]: https://rubygems.org/gems/dry-logic
|
|
3
|
-
[actions]: https://github.com/dry-rb/dry-logic/actions
|
|
4
|
-
|
|
5
|
-
# dry-logic [][gem] [][actions]
|
|
1
|
+
<!--- This file is synced from hanakai-rb/repo-sync -->
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
[actions]: https://github.com/dry-rb/dry-logic/actions
|
|
4
|
+
[chat]: https://discord.gg/naQApPAsZB
|
|
5
|
+
[forum]: https://discourse.hanakai.org
|
|
6
|
+
[rubygem]: https://rubygems.org/gems/dry-logic
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
* [API documentation](http://rubydoc.info/gems/dry-logic)
|
|
11
|
-
* [Forum](https://discourse.dry-rb.org)
|
|
8
|
+
# dry-logic [][rubygem] [][actions]
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
[][forum]
|
|
11
|
+
[][chat]
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
## Links
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
- [User documentation](https://dry-rb.org/gems/dry-logic)
|
|
16
|
+
- [API documentation](http://rubydoc.info/gems/dry-logic)
|
|
17
|
+
- [Forum](https://discourse.dry-rb.org)
|
|
19
18
|
|
|
20
19
|
## License
|
|
21
20
|
|
|
22
21
|
See `LICENSE` file.
|
|
22
|
+
|
data/dry-logic.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# This file is synced from hanakai-rb/repo-sync. To update it, edit repo-sync.yml.
|
|
4
4
|
|
|
5
5
|
lib = File.expand_path("lib", __dir__)
|
|
6
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
@@ -8,8 +8,8 @@ require "dry/logic/version"
|
|
|
8
8
|
|
|
9
9
|
Gem::Specification.new do |spec|
|
|
10
10
|
spec.name = "dry-logic"
|
|
11
|
-
spec.authors = ["
|
|
12
|
-
spec.email = ["
|
|
11
|
+
spec.authors = ["Hanakai team"]
|
|
12
|
+
spec.email = ["info@hanakai.org"]
|
|
13
13
|
spec.license = "MIT"
|
|
14
14
|
spec.version = Dry::Logic::VERSION.dup
|
|
15
15
|
|
|
@@ -17,23 +17,25 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
spec.description = spec.summary
|
|
18
18
|
spec.homepage = "https://dry-rb.org/gems/dry-logic"
|
|
19
19
|
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-logic.gemspec", "lib/**/*"]
|
|
20
|
-
spec.bindir = "
|
|
21
|
-
spec.executables = []
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = Dir["exe/*"].map { |f| File.basename(f) }
|
|
22
22
|
spec.require_paths = ["lib"]
|
|
23
23
|
|
|
24
|
-
spec.
|
|
24
|
+
spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
|
|
25
|
+
|
|
25
26
|
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-logic/blob/main/CHANGELOG.md"
|
|
26
27
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-logic"
|
|
27
28
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-logic/issues"
|
|
29
|
+
spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
|
|
28
30
|
|
|
29
|
-
spec.required_ruby_version = ">=
|
|
31
|
+
spec.required_ruby_version = ">= 3.1"
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
spec.add_runtime_dependency "bigdecimal"
|
|
32
34
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
|
33
|
-
spec.add_runtime_dependency "dry-core", "~> 1.
|
|
35
|
+
spec.add_runtime_dependency "dry-core", "~> 1.1"
|
|
34
36
|
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
|
|
35
|
-
|
|
36
37
|
spec.add_development_dependency "bundler"
|
|
37
38
|
spec.add_development_dependency "rake"
|
|
38
39
|
spec.add_development_dependency "rspec"
|
|
39
40
|
end
|
|
41
|
+
|
data/lib/dry/logic/builder.rb
CHANGED
|
@@ -28,8 +28,8 @@ module Dry
|
|
|
28
28
|
# p is_zero.call(1) # => false
|
|
29
29
|
# p is_zero.call(0) # => true
|
|
30
30
|
# p is_zero.call(-1) # => false
|
|
31
|
-
def call(&
|
|
32
|
-
Context.instance.call(&
|
|
31
|
+
def call(&)
|
|
32
|
+
Context.instance.call(&)
|
|
33
33
|
end
|
|
34
34
|
module_function :call
|
|
35
35
|
alias_method :build, :call
|
|
@@ -44,23 +44,23 @@ module Dry
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
# @see Builder#call
|
|
47
|
-
def call(&
|
|
48
|
-
instance_eval(&
|
|
47
|
+
def call(&)
|
|
48
|
+
instance_eval(&)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Defines custom predicate
|
|
52
52
|
#
|
|
53
53
|
# @name [Symbol] Name of predicate
|
|
54
54
|
# @Context [Proc]
|
|
55
|
-
def predicate(name, &
|
|
55
|
+
def predicate(name, context = nil, &block)
|
|
56
56
|
if singleton_class.method_defined?(name)
|
|
57
57
|
singleton_class.undef_method(name)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
predicate = Rule::Predicate.new(context || block)
|
|
61
61
|
|
|
62
62
|
define_singleton_method(name) do |*args|
|
|
63
|
-
|
|
63
|
+
predicate.curry(*args)
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -78,7 +78,7 @@ module Dry
|
|
|
78
78
|
|
|
79
79
|
Predicates::Methods.instance_methods(false).each do |name|
|
|
80
80
|
unless IGNORED_PREDICATES.include?(name)
|
|
81
|
-
predicate(name,
|
|
81
|
+
predicate(name, Predicates[name])
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
data/lib/dry/logic/predicates.rb
CHANGED
|
@@ -5,13 +5,13 @@ require "dry/core/constants"
|
|
|
5
5
|
require "bigdecimal"
|
|
6
6
|
require "bigdecimal/util"
|
|
7
7
|
require "date"
|
|
8
|
+
require "uri"
|
|
8
9
|
|
|
9
10
|
module Dry
|
|
10
11
|
module Logic
|
|
11
12
|
module Predicates
|
|
12
|
-
include Dry::Core::Constants
|
|
13
|
+
include ::Dry::Core::Constants
|
|
13
14
|
|
|
14
|
-
# rubocop:disable Metrics/ModuleLength
|
|
15
15
|
module Methods
|
|
16
16
|
def self.uuid_format(version)
|
|
17
17
|
::Regexp.new(<<~FORMAT.chomp, ::Regexp::IGNORECASE)
|
|
@@ -29,143 +29,99 @@ module Dry
|
|
|
29
29
|
|
|
30
30
|
UUIDv5 = uuid_format(5)
|
|
31
31
|
|
|
32
|
+
UUIDv6 = uuid_format(6)
|
|
33
|
+
|
|
34
|
+
UUIDv7 = uuid_format(7)
|
|
35
|
+
|
|
36
|
+
UUIDv8 = uuid_format(8)
|
|
37
|
+
|
|
32
38
|
def [](name)
|
|
33
39
|
method(name)
|
|
34
40
|
end
|
|
35
41
|
|
|
36
|
-
def type?(type, input)
|
|
37
|
-
input.is_a?(type)
|
|
38
|
-
end
|
|
42
|
+
def type?(type, input) = input.is_a?(type)
|
|
39
43
|
|
|
40
|
-
def nil?(input)
|
|
41
|
-
input.nil?
|
|
42
|
-
end
|
|
44
|
+
def nil?(input) = input.nil?
|
|
43
45
|
alias_method :none?, :nil?
|
|
44
46
|
|
|
45
|
-
def key?(name, input)
|
|
46
|
-
input.key?(name)
|
|
47
|
-
end
|
|
47
|
+
def key?(name, input) = input.key?(name)
|
|
48
48
|
|
|
49
|
-
def attr?(name, input)
|
|
50
|
-
input.respond_to?(name)
|
|
51
|
-
end
|
|
49
|
+
def attr?(name, input) = input.respond_to?(name)
|
|
52
50
|
|
|
53
51
|
def empty?(input)
|
|
54
52
|
case input
|
|
55
|
-
when String, Array, Hash then input.empty?
|
|
53
|
+
when ::String, ::Array, ::Hash then input.empty?
|
|
56
54
|
when nil then true
|
|
57
55
|
else
|
|
58
56
|
false
|
|
59
57
|
end
|
|
60
58
|
end
|
|
61
59
|
|
|
62
|
-
def filled?(input)
|
|
63
|
-
!empty?(input)
|
|
64
|
-
end
|
|
60
|
+
def filled?(input) = !empty?(input)
|
|
65
61
|
|
|
66
|
-
def bool?(input)
|
|
67
|
-
input.is_a?(TrueClass) || input.is_a?(FalseClass)
|
|
68
|
-
end
|
|
62
|
+
def bool?(input) = input.equal?(true) || input.equal?(false)
|
|
69
63
|
|
|
70
|
-
def date?(input)
|
|
71
|
-
input.is_a?(Date)
|
|
72
|
-
end
|
|
64
|
+
def date?(input) = input.is_a?(::Date)
|
|
73
65
|
|
|
74
|
-
def date_time?(input)
|
|
75
|
-
input.is_a?(DateTime)
|
|
76
|
-
end
|
|
66
|
+
def date_time?(input) = input.is_a?(::DateTime)
|
|
77
67
|
|
|
78
|
-
def time?(input)
|
|
79
|
-
input.is_a?(Time)
|
|
80
|
-
end
|
|
68
|
+
def time?(input) = input.is_a?(::Time)
|
|
81
69
|
|
|
82
70
|
def number?(input)
|
|
83
71
|
true if Float(input)
|
|
84
|
-
rescue ArgumentError, TypeError
|
|
72
|
+
rescue ::ArgumentError, ::TypeError
|
|
85
73
|
false
|
|
86
74
|
end
|
|
87
75
|
|
|
88
|
-
def int?(input)
|
|
89
|
-
input.is_a?(Integer)
|
|
90
|
-
end
|
|
76
|
+
def int?(input) = input.is_a?(::Integer)
|
|
91
77
|
|
|
92
|
-
def float?(input)
|
|
93
|
-
input.is_a?(Float)
|
|
94
|
-
end
|
|
78
|
+
def float?(input) = input.is_a?(::Float)
|
|
95
79
|
|
|
96
|
-
def decimal?(input)
|
|
97
|
-
input.is_a?(BigDecimal)
|
|
98
|
-
end
|
|
80
|
+
def decimal?(input) = input.is_a?(::BigDecimal)
|
|
99
81
|
|
|
100
|
-
def str?(input)
|
|
101
|
-
input.is_a?(String)
|
|
102
|
-
end
|
|
82
|
+
def str?(input) = input.is_a?(::String)
|
|
103
83
|
|
|
104
|
-
def hash?(input)
|
|
105
|
-
input.is_a?(Hash)
|
|
106
|
-
end
|
|
84
|
+
def hash?(input) = input.is_a?(::Hash)
|
|
107
85
|
|
|
108
|
-
def array?(input)
|
|
109
|
-
input.is_a?(Array)
|
|
110
|
-
end
|
|
86
|
+
def array?(input) = input.is_a?(::Array)
|
|
111
87
|
|
|
112
|
-
def odd?(input)
|
|
113
|
-
input.odd?
|
|
114
|
-
end
|
|
88
|
+
def odd?(input) = input.odd?
|
|
115
89
|
|
|
116
|
-
def even?(input)
|
|
117
|
-
input.even?
|
|
118
|
-
end
|
|
90
|
+
def even?(input) = input.even?
|
|
119
91
|
|
|
120
|
-
def lt?(num, input)
|
|
121
|
-
input < num
|
|
122
|
-
end
|
|
92
|
+
def lt?(num, input) = input < num
|
|
123
93
|
|
|
124
|
-
def gt?(num, input)
|
|
125
|
-
input > num
|
|
126
|
-
end
|
|
94
|
+
def gt?(num, input) = input > num
|
|
127
95
|
|
|
128
|
-
def lteq?(num, input)
|
|
129
|
-
!gt?(num, input)
|
|
130
|
-
end
|
|
96
|
+
def lteq?(num, input) = !gt?(num, input)
|
|
131
97
|
|
|
132
|
-
def gteq?(num, input)
|
|
133
|
-
!lt?(num, input)
|
|
134
|
-
end
|
|
98
|
+
def gteq?(num, input) = !lt?(num, input)
|
|
135
99
|
|
|
136
100
|
def size?(size, input)
|
|
137
101
|
case size
|
|
138
|
-
when Integer then size.equal?(input.size)
|
|
139
|
-
when Range, Array then size.include?(input.size)
|
|
102
|
+
when ::Integer then size.equal?(input.size)
|
|
103
|
+
when ::Range, ::Array then size.include?(input.size)
|
|
140
104
|
else
|
|
141
|
-
raise ArgumentError, "+#{size}+ is not supported type for size? predicate."
|
|
105
|
+
raise ::ArgumentError, "+#{size}+ is not supported type for size? predicate."
|
|
142
106
|
end
|
|
143
107
|
end
|
|
144
108
|
|
|
145
|
-
def min_size?(num, input)
|
|
146
|
-
input.size >= num
|
|
147
|
-
end
|
|
109
|
+
def min_size?(num, input) = input.size >= num
|
|
148
110
|
|
|
149
|
-
def max_size?(num, input)
|
|
150
|
-
input.size <= num
|
|
151
|
-
end
|
|
111
|
+
def max_size?(num, input) = input.size <= num
|
|
152
112
|
|
|
153
113
|
def bytesize?(size, input)
|
|
154
114
|
case size
|
|
155
|
-
when Integer then size.equal?(input.bytesize)
|
|
156
|
-
when Range, Array then size.include?(input.bytesize)
|
|
115
|
+
when ::Integer then size.equal?(input.bytesize)
|
|
116
|
+
when ::Range, ::Array then size.include?(input.bytesize)
|
|
157
117
|
else
|
|
158
|
-
raise ArgumentError, "+#{size}+ is not supported type for bytesize? predicate."
|
|
118
|
+
raise ::ArgumentError, "+#{size}+ is not supported type for bytesize? predicate."
|
|
159
119
|
end
|
|
160
120
|
end
|
|
161
121
|
|
|
162
|
-
def min_bytesize?(num, input)
|
|
163
|
-
input.bytesize >= num
|
|
164
|
-
end
|
|
122
|
+
def min_bytesize?(num, input) = input.bytesize >= num
|
|
165
123
|
|
|
166
|
-
def max_bytesize?(num, input)
|
|
167
|
-
input.bytesize <= num
|
|
168
|
-
end
|
|
124
|
+
def max_bytesize?(num, input) = input.bytesize <= num
|
|
169
125
|
|
|
170
126
|
def inclusion?(list, input)
|
|
171
127
|
deprecated(:inclusion?, :included_in?)
|
|
@@ -177,13 +133,9 @@ module Dry
|
|
|
177
133
|
excluded_from?(list, input)
|
|
178
134
|
end
|
|
179
135
|
|
|
180
|
-
def included_in?(list, input)
|
|
181
|
-
list.include?(input)
|
|
182
|
-
end
|
|
136
|
+
def included_in?(list, input) = list.include?(input)
|
|
183
137
|
|
|
184
|
-
def excluded_from?(list, input)
|
|
185
|
-
!list.include?(input)
|
|
186
|
-
end
|
|
138
|
+
def excluded_from?(list, input) = !list.include?(input)
|
|
187
139
|
|
|
188
140
|
def includes?(value, input)
|
|
189
141
|
if input.respond_to?(:include?)
|
|
@@ -191,13 +143,11 @@ module Dry
|
|
|
191
143
|
else
|
|
192
144
|
false
|
|
193
145
|
end
|
|
194
|
-
rescue TypeError
|
|
146
|
+
rescue ::TypeError
|
|
195
147
|
false
|
|
196
148
|
end
|
|
197
149
|
|
|
198
|
-
def excludes?(value, input)
|
|
199
|
-
!includes?(value, input)
|
|
200
|
-
end
|
|
150
|
+
def excludes?(value, input) = !includes?(value, input)
|
|
201
151
|
|
|
202
152
|
# This overrides Object#eql? so we need to make it compatible
|
|
203
153
|
def eql?(left, right = Undefined)
|
|
@@ -206,61 +156,50 @@ module Dry
|
|
|
206
156
|
left.eql?(right)
|
|
207
157
|
end
|
|
208
158
|
|
|
209
|
-
def is?(left, right)
|
|
210
|
-
left.equal?(right)
|
|
211
|
-
end
|
|
159
|
+
def is?(left, right) = left.equal?(right)
|
|
212
160
|
|
|
213
|
-
def not_eql?(left, right)
|
|
214
|
-
!left.eql?(right)
|
|
215
|
-
end
|
|
161
|
+
def not_eql?(left, right) = !left.eql?(right)
|
|
216
162
|
|
|
217
|
-
def true?(value)
|
|
218
|
-
value.equal?(true)
|
|
219
|
-
end
|
|
163
|
+
def true?(value) = value.equal?(true)
|
|
220
164
|
|
|
221
|
-
def false?(value)
|
|
222
|
-
value.equal?(false)
|
|
223
|
-
end
|
|
165
|
+
def false?(value) = value.equal?(false)
|
|
224
166
|
|
|
225
|
-
def format?(regex, input)
|
|
226
|
-
!input.nil? && regex.match?(input)
|
|
227
|
-
end
|
|
167
|
+
def format?(regex, input) = !input.nil? && regex.match?(input)
|
|
228
168
|
|
|
229
|
-
def case?(pattern, input)
|
|
230
|
-
# rubocop:disable Style/CaseEquality
|
|
231
|
-
pattern === input
|
|
232
|
-
# rubocop:enable Style/CaseEquality
|
|
233
|
-
end
|
|
169
|
+
def case?(pattern, input) = pattern === input # rubocop:disable Style/CaseEquality
|
|
234
170
|
|
|
235
|
-
def uuid_v1?(input)
|
|
236
|
-
format?(UUIDv1, input)
|
|
237
|
-
end
|
|
171
|
+
def uuid_v1?(input) = format?(UUIDv1, input)
|
|
238
172
|
|
|
239
|
-
def uuid_v2?(input)
|
|
240
|
-
format?(UUIDv2, input)
|
|
241
|
-
end
|
|
173
|
+
def uuid_v2?(input) = format?(UUIDv2, input)
|
|
242
174
|
|
|
243
|
-
def uuid_v3?(input)
|
|
244
|
-
format?(UUIDv3, input)
|
|
245
|
-
end
|
|
175
|
+
def uuid_v3?(input) = format?(UUIDv3, input)
|
|
246
176
|
|
|
247
|
-
def uuid_v4?(input)
|
|
248
|
-
format?(UUIDv4, input)
|
|
249
|
-
end
|
|
177
|
+
def uuid_v4?(input) = format?(UUIDv4, input)
|
|
250
178
|
|
|
251
|
-
def uuid_v5?(input)
|
|
252
|
-
format?(UUIDv5, input)
|
|
253
|
-
end
|
|
179
|
+
def uuid_v5?(input) = format?(UUIDv5, input)
|
|
254
180
|
|
|
255
|
-
def
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
181
|
+
def uuid_v6?(input) = format?(UUIDv6, input)
|
|
182
|
+
|
|
183
|
+
def uuid_v7?(input) = format?(UUIDv7, input)
|
|
184
|
+
|
|
185
|
+
def uuid_v8?(input) = format?(UUIDv8, input)
|
|
259
186
|
|
|
260
|
-
|
|
261
|
-
|
|
187
|
+
# `make_regexp` builds an unanchored pattern meant for extracting URIs from text, so it is
|
|
188
|
+
# anchored here to require the whole input to be a URI with a permitted scheme.
|
|
189
|
+
if defined?(::URI::RFC2396_PARSER)
|
|
190
|
+
def uri?(schemes, input)
|
|
191
|
+
uri_format = ::URI::RFC2396_PARSER.make_regexp(schemes)
|
|
192
|
+
format?(/\A(?:#{uri_format})\z/, input)
|
|
193
|
+
end
|
|
194
|
+
else
|
|
195
|
+
def uri?(schemes, input)
|
|
196
|
+
uri_format = ::URI::DEFAULT_PARSER.make_regexp(schemes)
|
|
197
|
+
format?(/\A(?:#{uri_format})\z/, input)
|
|
198
|
+
end
|
|
262
199
|
end
|
|
263
200
|
|
|
201
|
+
def uri_rfc3986?(input) = format?(::URI::RFC3986_Parser::RFC3986_URI, input)
|
|
202
|
+
|
|
264
203
|
# This overrides Object#respond_to? so we need to make it compatible
|
|
265
204
|
def respond_to?(method, input = Undefined)
|
|
266
205
|
return super if input.equal?(Undefined)
|
|
@@ -268,8 +207,8 @@ module Dry
|
|
|
268
207
|
input.respond_to?(method)
|
|
269
208
|
end
|
|
270
209
|
|
|
271
|
-
def predicate(name, &
|
|
272
|
-
define_singleton_method(name, &
|
|
210
|
+
def predicate(name, &)
|
|
211
|
+
define_singleton_method(name, &)
|
|
273
212
|
end
|
|
274
213
|
|
|
275
214
|
def deprecated(name, in_favor_of)
|
data/lib/dry/logic/result.rb
CHANGED
|
@@ -29,17 +29,11 @@ module Dry
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def constant?
|
|
33
|
-
arity.zero?
|
|
34
|
-
end
|
|
32
|
+
def constant? = arity.zero?
|
|
35
33
|
|
|
36
|
-
def variable_arity?
|
|
37
|
-
arity.negative?
|
|
38
|
-
end
|
|
34
|
+
def variable_arity? = arity.negative?
|
|
39
35
|
|
|
40
|
-
def curried?
|
|
41
|
-
!curried.zero?
|
|
42
|
-
end
|
|
36
|
+
def curried? = !curried.zero?
|
|
43
37
|
|
|
44
38
|
def unapplied
|
|
45
39
|
if variable_arity?
|
|
@@ -116,26 +110,26 @@ module Dry
|
|
|
116
110
|
application = "@predicate[#{(curried_args + unapplied_args + splat).join(", ")}]"
|
|
117
111
|
|
|
118
112
|
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
|
119
|
-
def call(#{parameters})
|
|
120
|
-
if #{application}
|
|
121
|
-
Result::SUCCESS
|
|
122
|
-
else
|
|
123
|
-
Result.new(false, id) { ast(#{parameters}) }
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def [](#{parameters})
|
|
128
|
-
#{application}
|
|
129
|
-
end
|
|
113
|
+
def call(#{parameters}) # def call(input0, input1, *rest)
|
|
114
|
+
if #{application} # if @predicate[@arg0, @arg1, input0, input1, *rest]
|
|
115
|
+
Result::SUCCESS # ::Dry::Logic::Result::Success
|
|
116
|
+
else # else
|
|
117
|
+
Result.new(false, id) { ast(#{parameters}) } # ::Dry::Logic::Result.new(false, id) { ast(input0, input1, *rest) }
|
|
118
|
+
end # end
|
|
119
|
+
end # end
|
|
120
|
+
#
|
|
121
|
+
def [](#{parameters}) # def [](@arg0, @arg1, input0, input1, *rest)
|
|
122
|
+
#{application} # @predicate[@arg0, @arg1, input0, input1, *rest]
|
|
123
|
+
end # end
|
|
130
124
|
RUBY
|
|
131
125
|
end
|
|
132
126
|
|
|
133
127
|
def curried_args
|
|
134
|
-
@curried_args ||= ::Array.new(curried) {
|
|
128
|
+
@curried_args ||= ::Array.new(curried) { "@arg#{_1}" }
|
|
135
129
|
end
|
|
136
130
|
|
|
137
131
|
def unapplied_args
|
|
138
|
-
@unapplied_args ||= ::Array.new(unapplied) {
|
|
132
|
+
@unapplied_args ||= ::Array.new(unapplied) { "input#{_1}" }
|
|
139
133
|
end
|
|
140
134
|
end
|
|
141
135
|
end
|
data/lib/dry/logic/rule.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Dry
|
|
|
14
14
|
|
|
15
15
|
class Rule
|
|
16
16
|
include Core::Constants
|
|
17
|
-
include Dry::Equalizer(:predicate, :options)
|
|
17
|
+
include ::Dry::Equalizer(:predicate, :options)
|
|
18
18
|
include Operators
|
|
19
19
|
|
|
20
20
|
attr_reader :predicate
|
|
@@ -32,7 +32,7 @@ module Dry
|
|
|
32
32
|
def self.specialize(arity, curried, base = Rule)
|
|
33
33
|
base.interfaces.fetch_or_store([arity, curried]) do
|
|
34
34
|
interface = Interface.new(arity, curried)
|
|
35
|
-
klass = Class.new(base) { include interface }
|
|
35
|
+
klass = ::Class.new(base) { include interface }
|
|
36
36
|
base.const_set("#{base.name.split("::").last}#{interface.name}", klass)
|
|
37
37
|
klass
|
|
38
38
|
end
|
data/lib/dry/logic/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dry-logic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
bindir: bin
|
|
7
|
+
- Hanakai team
|
|
8
|
+
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: bigdecimal
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
13
26
|
- !ruby/object:Gem::Dependency
|
|
14
27
|
name: concurrent-ruby
|
|
15
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -30,20 +43,14 @@ dependencies:
|
|
|
30
43
|
requirements:
|
|
31
44
|
- - "~>"
|
|
32
45
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '1.
|
|
34
|
-
- - "<"
|
|
35
|
-
- !ruby/object:Gem::Version
|
|
36
|
-
version: '2'
|
|
46
|
+
version: '1.1'
|
|
37
47
|
type: :runtime
|
|
38
48
|
prerelease: false
|
|
39
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
40
50
|
requirements:
|
|
41
51
|
- - "~>"
|
|
42
52
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: '1.
|
|
44
|
-
- - "<"
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: '2'
|
|
53
|
+
version: '1.1'
|
|
47
54
|
- !ruby/object:Gem::Dependency
|
|
48
55
|
name: zeitwerk
|
|
49
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -102,10 +109,13 @@ dependencies:
|
|
|
102
109
|
version: '0'
|
|
103
110
|
description: Predicate logic with rule composition
|
|
104
111
|
email:
|
|
105
|
-
-
|
|
112
|
+
- info@hanakai.org
|
|
106
113
|
executables: []
|
|
107
114
|
extensions: []
|
|
108
|
-
extra_rdoc_files:
|
|
115
|
+
extra_rdoc_files:
|
|
116
|
+
- CHANGELOG.md
|
|
117
|
+
- LICENSE
|
|
118
|
+
- README.md
|
|
109
119
|
files:
|
|
110
120
|
- CHANGELOG.md
|
|
111
121
|
- LICENSE
|
|
@@ -141,11 +151,10 @@ homepage: https://dry-rb.org/gems/dry-logic
|
|
|
141
151
|
licenses:
|
|
142
152
|
- MIT
|
|
143
153
|
metadata:
|
|
144
|
-
allowed_push_host: https://rubygems.org
|
|
145
154
|
changelog_uri: https://github.com/dry-rb/dry-logic/blob/main/CHANGELOG.md
|
|
146
155
|
source_code_uri: https://github.com/dry-rb/dry-logic
|
|
147
156
|
bug_tracker_uri: https://github.com/dry-rb/dry-logic/issues
|
|
148
|
-
|
|
157
|
+
funding_uri: https://github.com/sponsors/hanami
|
|
149
158
|
rdoc_options: []
|
|
150
159
|
require_paths:
|
|
151
160
|
- lib
|
|
@@ -153,15 +162,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
153
162
|
requirements:
|
|
154
163
|
- - ">="
|
|
155
164
|
- !ruby/object:Gem::Version
|
|
156
|
-
version:
|
|
165
|
+
version: '3.1'
|
|
157
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
167
|
requirements:
|
|
159
168
|
- - ">="
|
|
160
169
|
- !ruby/object:Gem::Version
|
|
161
170
|
version: '0'
|
|
162
171
|
requirements: []
|
|
163
|
-
rubygems_version: 3.
|
|
164
|
-
signing_key:
|
|
172
|
+
rubygems_version: 3.6.9
|
|
165
173
|
specification_version: 4
|
|
166
174
|
summary: Predicate logic with rule composition
|
|
167
175
|
test_files: []
|