dry-logic 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/dry-logic.rb +1 -1
- data/lib/dry/logic.rb +2 -2
- data/lib/dry/logic/evaluator.rb +1 -1
- data/lib/dry/logic/operations.rb +11 -11
- data/lib/dry/logic/operations/abstract.rb +3 -3
- data/lib/dry/logic/operations/and.rb +3 -3
- data/lib/dry/logic/operations/attr.rb +1 -1
- data/lib/dry/logic/operations/binary.rb +1 -1
- data/lib/dry/logic/operations/check.rb +3 -3
- data/lib/dry/logic/operations/each.rb +2 -2
- data/lib/dry/logic/operations/implication.rb +2 -2
- data/lib/dry/logic/operations/key.rb +3 -3
- data/lib/dry/logic/operations/negation.rb +2 -2
- data/lib/dry/logic/operations/or.rb +2 -2
- data/lib/dry/logic/operations/set.rb +3 -3
- data/lib/dry/logic/operations/unary.rb +1 -1
- data/lib/dry/logic/operations/xor.rb +2 -2
- data/lib/dry/logic/operators.rb +4 -4
- data/lib/dry/logic/predicates.rb +31 -6
- data/lib/dry/logic/result.rb +2 -2
- data/lib/dry/logic/rule.rb +8 -8
- data/lib/dry/logic/rule/interface.rb +8 -8
- data/lib/dry/logic/rule/predicate.rb +3 -3
- data/lib/dry/logic/rule_compiler.rb +3 -3
- data/lib/dry/logic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 828bea190b3733a29b940d0fa6bbb1270bb12ee6bbbef77d1ce6bbfd7ff11a27
|
4
|
+
data.tar.gz: 319087e0aa57490d3a0bbff76efd6b01119a55135de7dbe0829d64cfee604d82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e3d3d3d7c486aec5e4c01ebc15f90ba485dfe4d10086c11a732ea3ffac5749de02b4ecc0fb0beafe8bcc593fa07286c1c8c30f2973baaf70598a3f212e949eb
|
7
|
+
data.tar.gz: beb0445b376e9e8f545615d69af4c7cc1ad76db1ac55de9bd54784d8ff914165afec81ce174843efac5cffeda8bba494bca9e686d75052f00dee87abbfef03b3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 1.0.7 2020-08-13
|
2
|
+
|
3
|
+
|
4
|
+
### Added
|
5
|
+
|
6
|
+
- A new `uri?` predicate that you can use to verify `URI` strings, ie `uri?("https", "https://dry-rb.org")` (@nerburish)
|
7
|
+
- New predicates: `uuid_v1?`, `uuid_v2?`, `uuid_v3?` and `uuid_v5?` (via #75) (@jamesbrauman)
|
8
|
+
|
9
|
+
|
10
|
+
[Compare v1.0.6...v1.0.7](https://github.com/dry-rb/dry-logic/compare/v1.0.6...v1.0.7)
|
11
|
+
|
1
12
|
## 1.0.6 2020-02-10
|
2
13
|
|
3
14
|
|
data/lib/dry-logic.rb
CHANGED
data/lib/dry/logic.rb
CHANGED
data/lib/dry/logic/evaluator.rb
CHANGED
data/lib/dry/logic/operations.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "dry/logic/operations/and"
|
4
|
+
require "dry/logic/operations/or"
|
5
|
+
require "dry/logic/operations/xor"
|
6
|
+
require "dry/logic/operations/implication"
|
7
|
+
require "dry/logic/operations/negation"
|
8
8
|
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
9
|
+
require "dry/logic/operations/key"
|
10
|
+
require "dry/logic/operations/attr"
|
11
|
+
require "dry/logic/operations/each"
|
12
|
+
require "dry/logic/operations/set"
|
13
|
+
require "dry/logic/operations/check"
|
14
14
|
|
15
|
-
require
|
15
|
+
require "dry/logic/operators"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "dry/logic/operations/binary"
|
4
|
+
require "dry/logic/result"
|
5
5
|
|
6
6
|
module Dry
|
7
7
|
module Logic
|
@@ -17,7 +17,7 @@ module Dry
|
|
17
17
|
def type
|
18
18
|
:and
|
19
19
|
end
|
20
|
-
|
20
|
+
alias_method :operator, :type
|
21
21
|
|
22
22
|
def call(input)
|
23
23
|
left_result = left.(input)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "dry/logic/operations/unary"
|
4
|
+
require "dry/logic/evaluator"
|
5
|
+
require "dry/logic/result"
|
6
6
|
|
7
7
|
module Dry
|
8
8
|
module Logic
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "dry/logic/operations/unary"
|
4
|
+
require "dry/logic/evaluator"
|
5
|
+
require "dry/logic/result"
|
6
6
|
|
7
7
|
module Dry
|
8
8
|
module Logic
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "dry/logic/operations/abstract"
|
4
|
+
require "dry/logic/result"
|
5
5
|
|
6
6
|
module Dry
|
7
7
|
module Logic
|
@@ -29,7 +29,7 @@ module Dry
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def to_s
|
32
|
-
"#{type}(#{rules.map(&:to_s).join(
|
32
|
+
"#{type}(#{rules.map(&:to_s).join(", ")})"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/dry/logic/operators.rb
CHANGED
@@ -6,22 +6,22 @@ module Dry
|
|
6
6
|
def and(other)
|
7
7
|
Operations::And.new(self, other)
|
8
8
|
end
|
9
|
-
|
9
|
+
alias_method :&, :and
|
10
10
|
|
11
11
|
def or(other)
|
12
12
|
Operations::Or.new(self, other)
|
13
13
|
end
|
14
|
-
|
14
|
+
alias_method :|, :or
|
15
15
|
|
16
16
|
def xor(other)
|
17
17
|
Operations::Xor.new(self, other)
|
18
18
|
end
|
19
|
-
|
19
|
+
alias_method :^, :xor
|
20
20
|
|
21
21
|
def then(other)
|
22
22
|
Operations::Implication.new(self, other)
|
23
23
|
end
|
24
|
-
|
24
|
+
alias_method :>, :then
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/dry/logic/predicates.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "bigdecimal"
|
4
|
+
require "bigdecimal/util"
|
5
|
+
require "date"
|
6
6
|
|
7
7
|
module Dry
|
8
8
|
module Logic
|
@@ -13,7 +13,7 @@ module Dry
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def type?(type, input)
|
16
|
-
input.
|
16
|
+
input.is_a?(type)
|
17
17
|
end
|
18
18
|
|
19
19
|
def nil?(input)
|
@@ -147,12 +147,12 @@ module Dry
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def inclusion?(list, input)
|
150
|
-
::Kernel.warn
|
150
|
+
::Kernel.warn "inclusion is deprecated - use included_in instead."
|
151
151
|
included_in?(list, input)
|
152
152
|
end
|
153
153
|
|
154
154
|
def exclusion?(list, input)
|
155
|
-
::Kernel.warn
|
155
|
+
::Kernel.warn "exclusion is deprecated - use excluded_from instead."
|
156
156
|
excluded_from?(list, input)
|
157
157
|
end
|
158
158
|
|
@@ -206,11 +206,36 @@ module Dry
|
|
206
206
|
pattern === input
|
207
207
|
end
|
208
208
|
|
209
|
+
def uuid_v1?(input)
|
210
|
+
uuid_v1_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
|
211
|
+
format?(uuid_v1_format, input)
|
212
|
+
end
|
213
|
+
|
214
|
+
def uuid_v2?(input)
|
215
|
+
uuid_v2_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
|
216
|
+
format?(uuid_v2_format, input)
|
217
|
+
end
|
218
|
+
|
219
|
+
def uuid_v3?(input)
|
220
|
+
uuid_v3_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
|
221
|
+
format?(uuid_v3_format, input)
|
222
|
+
end
|
223
|
+
|
209
224
|
def uuid_v4?(input)
|
210
225
|
uuid_v4_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
|
211
226
|
format?(uuid_v4_format, input)
|
212
227
|
end
|
213
228
|
|
229
|
+
def uuid_v5?(input)
|
230
|
+
uuid_v5_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
|
231
|
+
format?(uuid_v5_format, input)
|
232
|
+
end
|
233
|
+
|
234
|
+
def uri?(schemes, input)
|
235
|
+
uri_format = URI::DEFAULT_PARSER.make_regexp(schemes)
|
236
|
+
format?(uri_format, input)
|
237
|
+
end
|
238
|
+
|
214
239
|
def respond_to?(method, input)
|
215
240
|
input.respond_to?(method)
|
216
241
|
end
|
data/lib/dry/logic/result.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dry/core/constants"
|
4
4
|
|
5
5
|
module Dry
|
6
6
|
module Logic
|
@@ -69,7 +69,7 @@ module Dry
|
|
69
69
|
if args.empty?
|
70
70
|
name.to_s
|
71
71
|
else
|
72
|
-
"#{name}(#{args.map(&:last).map(&:inspect).join(
|
72
|
+
"#{name}(#{args.map(&:last).map(&:inspect).join(", ")})"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
data/lib/dry/logic/rule.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require "concurrent/map"
|
4
|
+
require "dry/core/constants"
|
5
|
+
require "dry/equalizer"
|
6
|
+
require "dry/logic/operations"
|
7
|
+
require "dry/logic/result"
|
8
|
+
require "dry/logic/rule/interface"
|
9
9
|
|
10
10
|
module Dry
|
11
11
|
module Logic
|
@@ -38,13 +38,13 @@ module Dry
|
|
38
38
|
base.interfaces.fetch_or_store([arity, curried]) do
|
39
39
|
interface = Interface.new(arity, curried)
|
40
40
|
klass = Class.new(base) { include interface }
|
41
|
-
base.const_set("#{base.name.split(
|
41
|
+
base.const_set("#{base.name.split("::").last}#{interface.name}", klass)
|
42
42
|
klass
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.build(predicate, args: EMPTY_ARRAY, arity: predicate.arity, **options)
|
47
|
-
specialize(arity, args.size).new(predicate, {
|
47
|
+
specialize(arity, args.size).new(predicate, {args: args, arity: arity, **options})
|
48
48
|
end
|
49
49
|
|
50
50
|
def initialize(predicate, options = EMPTY_HASH)
|
@@ -49,9 +49,9 @@ module Dry
|
|
49
49
|
|
50
50
|
def name
|
51
51
|
if constant?
|
52
|
-
|
52
|
+
"Constant"
|
53
53
|
else
|
54
|
-
arity_str = variable_arity? ?
|
54
|
+
arity_str = variable_arity? ? "VariableArity" : "#{arity}Arity"
|
55
55
|
curried_str = curried? ? "#{curried}Curried" : EMPTY_STRING
|
56
56
|
|
57
57
|
"#{arity_str}#{curried_str}"
|
@@ -61,9 +61,9 @@ module Dry
|
|
61
61
|
def define_constructor
|
62
62
|
assignment =
|
63
63
|
if curried.equal?(1)
|
64
|
-
|
64
|
+
"@arg0 = @args[0]"
|
65
65
|
else
|
66
|
-
"#{curried_args.join(
|
66
|
+
"#{curried_args.join(", ")} = @args"
|
67
67
|
end
|
68
68
|
|
69
69
|
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
@@ -94,9 +94,9 @@ module Dry
|
|
94
94
|
def define_splat_application
|
95
95
|
application =
|
96
96
|
if curried?
|
97
|
-
"@predicate[#{curried_args.join(
|
97
|
+
"@predicate[#{curried_args.join(", ")}, *input]"
|
98
98
|
else
|
99
|
-
|
99
|
+
"@predicate[*input]"
|
100
100
|
end
|
101
101
|
|
102
102
|
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
@@ -115,8 +115,8 @@ module Dry
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def define_fixed_application
|
118
|
-
parameters = unapplied_args.join(
|
119
|
-
application = "@predicate[#{(curried_args + unapplied_args).join(
|
118
|
+
parameters = unapplied_args.join(", ")
|
119
|
+
application = "@predicate[#{(curried_args + unapplied_args).join(", ")}]"
|
120
120
|
|
121
121
|
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
122
122
|
def call(#{parameters})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dry/logic/rule"
|
4
4
|
|
5
5
|
module Dry
|
6
6
|
module Logic
|
@@ -19,9 +19,9 @@ module Dry
|
|
19
19
|
|
20
20
|
def to_s
|
21
21
|
if args.size > 0
|
22
|
-
"#{name}(#{args.map(&:inspect).join(
|
22
|
+
"#{name}(#{args.map(&:inspect).join(", ")})"
|
23
23
|
else
|
24
|
-
|
24
|
+
name.to_s
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/lib/dry/logic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|