dry-logic 0.6.1 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +121 -22
- data/LICENSE +1 -1
- data/README.md +12 -14
- data/dry-logic.gemspec +29 -14
- data/lib/dry-logic.rb +2 -0
- data/lib/dry/logic.rb +2 -0
- data/lib/dry/logic/appliable.rb +2 -0
- data/lib/dry/logic/evaluator.rb +2 -0
- data/lib/dry/logic/operations.rb +2 -0
- data/lib/dry/logic/operations/abstract.rb +5 -3
- data/lib/dry/logic/operations/and.rb +3 -1
- data/lib/dry/logic/operations/attr.rb +2 -0
- data/lib/dry/logic/operations/binary.rb +2 -0
- data/lib/dry/logic/operations/check.rb +3 -1
- data/lib/dry/logic/operations/each.rb +2 -0
- data/lib/dry/logic/operations/implication.rb +2 -0
- data/lib/dry/logic/operations/key.rb +4 -2
- data/lib/dry/logic/operations/negation.rb +2 -0
- data/lib/dry/logic/operations/or.rb +2 -0
- data/lib/dry/logic/operations/set.rb +2 -0
- data/lib/dry/logic/operations/unary.rb +2 -0
- data/lib/dry/logic/operations/xor.rb +2 -0
- data/lib/dry/logic/operators.rb +2 -0
- data/lib/dry/logic/predicates.rb +39 -21
- data/lib/dry/logic/result.rb +2 -0
- data/lib/dry/logic/rule.rb +5 -3
- data/lib/dry/logic/rule/interface.rb +3 -1
- data/lib/dry/logic/rule/predicate.rb +2 -0
- data/lib/dry/logic/rule_compiler.rb +2 -0
- data/lib/dry/logic/version.rb +3 -1
- metadata +11 -128
- data/.codeclimate.yml +0 -15
- data/.gitignore +0 -8
- data/.rspec +0 -3
- data/.travis.yml +0 -31
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -13
- data/Rakefile +0 -12
- data/benchmarks/rule_application.rb +0 -28
- data/benchmarks/setup.rb +0 -11
- data/bin/console +0 -10
- data/examples/basic.rb +0 -14
- data/spec/integration/result_spec.rb +0 -59
- data/spec/integration/rule_spec.rb +0 -53
- data/spec/shared/predicates.rb +0 -57
- data/spec/shared/rule.rb +0 -72
- data/spec/spec_helper.rb +0 -34
- data/spec/support/mutant.rb +0 -9
- data/spec/unit/operations/and_spec.rb +0 -68
- data/spec/unit/operations/attr_spec.rb +0 -27
- data/spec/unit/operations/check_spec.rb +0 -49
- data/spec/unit/operations/each_spec.rb +0 -47
- data/spec/unit/operations/implication_spec.rb +0 -30
- data/spec/unit/operations/key_spec.rb +0 -133
- data/spec/unit/operations/negation_spec.rb +0 -49
- data/spec/unit/operations/or_spec.rb +0 -73
- data/spec/unit/operations/set_spec.rb +0 -41
- data/spec/unit/operations/xor_spec.rb +0 -61
- data/spec/unit/predicates/array_spec.rb +0 -41
- data/spec/unit/predicates/attr_spec.rb +0 -29
- data/spec/unit/predicates/bool_spec.rb +0 -34
- data/spec/unit/predicates/case_spec.rb +0 -33
- data/spec/unit/predicates/date_spec.rb +0 -31
- data/spec/unit/predicates/date_time_spec.rb +0 -31
- data/spec/unit/predicates/decimal_spec.rb +0 -32
- data/spec/unit/predicates/empty_spec.rb +0 -38
- data/spec/unit/predicates/eql_spec.rb +0 -21
- data/spec/unit/predicates/even_spec.rb +0 -31
- data/spec/unit/predicates/excluded_from_spec.rb +0 -35
- data/spec/unit/predicates/excludes_spec.rb +0 -56
- data/spec/unit/predicates/false_spec.rb +0 -35
- data/spec/unit/predicates/filled_spec.rb +0 -38
- data/spec/unit/predicates/float_spec.rb +0 -31
- data/spec/unit/predicates/format_spec.rb +0 -21
- data/spec/unit/predicates/gt_spec.rb +0 -40
- data/spec/unit/predicates/gteq_spec.rb +0 -40
- data/spec/unit/predicates/included_in_spec.rb +0 -35
- data/spec/unit/predicates/includes_spec.rb +0 -24
- data/spec/unit/predicates/int_spec.rb +0 -34
- data/spec/unit/predicates/key_spec.rb +0 -29
- data/spec/unit/predicates/lt_spec.rb +0 -40
- data/spec/unit/predicates/lteq_spec.rb +0 -40
- data/spec/unit/predicates/max_size_spec.rb +0 -49
- data/spec/unit/predicates/min_size_spec.rb +0 -49
- data/spec/unit/predicates/none_spec.rb +0 -28
- data/spec/unit/predicates/not_eql_spec.rb +0 -21
- data/spec/unit/predicates/number_spec.rb +0 -37
- data/spec/unit/predicates/odd_spec.rb +0 -31
- data/spec/unit/predicates/size_spec.rb +0 -55
- data/spec/unit/predicates/str_spec.rb +0 -32
- data/spec/unit/predicates/time_spec.rb +0 -31
- data/spec/unit/predicates/true_spec.rb +0 -35
- data/spec/unit/predicates/type_spec.rb +0 -35
- data/spec/unit/predicates_spec.rb +0 -23
- data/spec/unit/rule/predicate_spec.rb +0 -53
- data/spec/unit/rule_compiler_spec.rb +0 -127
- data/spec/unit/rule_spec.rb +0 -211
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/logic/operations/unary'
|
2
4
|
require 'dry/logic/evaluator'
|
3
5
|
require 'dry/logic/result'
|
@@ -15,7 +17,7 @@ module Dry
|
|
15
17
|
keys = options.fetch(:keys)
|
16
18
|
evaluator = Evaluator::Set.new(keys)
|
17
19
|
|
18
|
-
super(rule, options
|
20
|
+
super(rule, **options, evaluator: evaluator)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/logic/operations/unary'
|
2
4
|
require 'dry/logic/evaluator'
|
3
5
|
require 'dry/logic/result'
|
@@ -10,13 +12,13 @@ module Dry
|
|
10
12
|
|
11
13
|
attr_reader :path
|
12
14
|
|
13
|
-
def self.new(rules, options)
|
15
|
+
def self.new(rules, **options)
|
14
16
|
if options[:evaluator]
|
15
17
|
super
|
16
18
|
else
|
17
19
|
name = options.fetch(:name)
|
18
20
|
eval = options.fetch(:evaluator, evaluator(name))
|
19
|
-
super(rules, options
|
21
|
+
super(rules, **options, evaluator: eval, path: name)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
data/lib/dry/logic/operators.rb
CHANGED
data/lib/dry/logic/predicates.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bigdecimal'
|
2
4
|
require 'bigdecimal/util'
|
3
5
|
require 'date'
|
@@ -57,11 +59,9 @@ module Dry
|
|
57
59
|
end
|
58
60
|
|
59
61
|
def number?(input)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
false
|
64
|
-
end
|
62
|
+
true if Float(input)
|
63
|
+
rescue ArgumentError, TypeError
|
64
|
+
false
|
65
65
|
end
|
66
66
|
|
67
67
|
def int?(input)
|
@@ -114,7 +114,7 @@ module Dry
|
|
114
114
|
|
115
115
|
def size?(size, input)
|
116
116
|
case size
|
117
|
-
when Integer then size
|
117
|
+
when Integer then size.equal?(input.size)
|
118
118
|
when Range, Array then size.include?(input.size)
|
119
119
|
else
|
120
120
|
raise ArgumentError, "+#{size}+ is not supported type for size? predicate."
|
@@ -129,6 +129,23 @@ module Dry
|
|
129
129
|
input.size <= num
|
130
130
|
end
|
131
131
|
|
132
|
+
def bytesize?(size, input)
|
133
|
+
case size
|
134
|
+
when Integer then size.equal?(input.bytesize)
|
135
|
+
when Range, Array then size.include?(input.bytesize)
|
136
|
+
else
|
137
|
+
raise ArgumentError, "+#{size}+ is not supported type for bytesize? predicate."
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def min_bytesize?(num, input)
|
142
|
+
input.bytesize >= num
|
143
|
+
end
|
144
|
+
|
145
|
+
def max_bytesize?(num, input)
|
146
|
+
input.bytesize <= num
|
147
|
+
end
|
148
|
+
|
132
149
|
def inclusion?(list, input)
|
133
150
|
::Kernel.warn 'inclusion is deprecated - use included_in instead.'
|
134
151
|
included_in?(list, input)
|
@@ -148,15 +165,13 @@ module Dry
|
|
148
165
|
end
|
149
166
|
|
150
167
|
def includes?(value, input)
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
else
|
155
|
-
false
|
156
|
-
end
|
157
|
-
rescue TypeError
|
168
|
+
if input.respond_to?(:include?)
|
169
|
+
input.include?(value)
|
170
|
+
else
|
158
171
|
false
|
159
172
|
end
|
173
|
+
rescue TypeError
|
174
|
+
false
|
160
175
|
end
|
161
176
|
|
162
177
|
def excludes?(value, input)
|
@@ -183,20 +198,23 @@ module Dry
|
|
183
198
|
value.equal?(false)
|
184
199
|
end
|
185
200
|
|
186
|
-
|
187
|
-
|
188
|
-
!regex.match(input).nil?
|
189
|
-
end
|
190
|
-
else
|
191
|
-
def format?(regex, input)
|
192
|
-
regex.match?(input)
|
193
|
-
end
|
201
|
+
def format?(regex, input)
|
202
|
+
!input.nil? && regex.match?(input)
|
194
203
|
end
|
195
204
|
|
196
205
|
def case?(pattern, input)
|
197
206
|
pattern === input
|
198
207
|
end
|
199
208
|
|
209
|
+
def uuid_v4?(input)
|
210
|
+
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
|
+
format?(uuid_v4_format, input)
|
212
|
+
end
|
213
|
+
|
214
|
+
def respond_to?(method, input)
|
215
|
+
input.respond_to?(method)
|
216
|
+
end
|
217
|
+
|
200
218
|
def predicate(name, &block)
|
201
219
|
define_singleton_method(name, &block)
|
202
220
|
end
|
data/lib/dry/logic/result.rb
CHANGED
data/lib/dry/logic/rule.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'concurrent/map'
|
2
4
|
require 'dry/core/constants'
|
3
5
|
require 'dry/equalizer'
|
@@ -66,11 +68,11 @@ module Dry
|
|
66
68
|
|
67
69
|
def bind(object)
|
68
70
|
if predicate.respond_to?(:bind)
|
69
|
-
self.class.build(predicate.bind(object), options)
|
71
|
+
self.class.build(predicate.bind(object), **options)
|
70
72
|
else
|
71
73
|
self.class.build(
|
72
74
|
-> *args { object.instance_exec(*args, &predicate) },
|
73
|
-
options
|
75
|
+
**options, arity: arity, parameters: parameters
|
74
76
|
)
|
75
77
|
end
|
76
78
|
end
|
@@ -80,7 +82,7 @@ module Dry
|
|
80
82
|
end
|
81
83
|
|
82
84
|
def with(new_opts)
|
83
|
-
self.class.build(predicate, options
|
85
|
+
self.class.build(predicate, **options, **new_opts)
|
84
86
|
end
|
85
87
|
|
86
88
|
def parameters
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module Logic
|
3
5
|
class Rule
|
@@ -114,7 +116,7 @@ module Dry
|
|
114
116
|
|
115
117
|
def define_fixed_application
|
116
118
|
parameters = unapplied_args.join(', ')
|
117
|
-
application = "@predicate[#{
|
119
|
+
application = "@predicate[#{(curried_args + unapplied_args).join(', ')}]"
|
118
120
|
|
119
121
|
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
120
122
|
def call(#{parameters})
|
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: 0.6
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -94,28 +94,17 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
97
|
+
description: Predicate logic with rule composition
|
98
98
|
email:
|
99
99
|
- piotr.solnica@gmail.com
|
100
100
|
executables: []
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- ".codeclimate.yml"
|
105
|
-
- ".gitignore"
|
106
|
-
- ".rspec"
|
107
|
-
- ".travis.yml"
|
108
104
|
- CHANGELOG.md
|
109
|
-
- CONTRIBUTING.md
|
110
|
-
- Gemfile
|
111
105
|
- LICENSE
|
112
106
|
- README.md
|
113
|
-
- Rakefile
|
114
|
-
- benchmarks/rule_application.rb
|
115
|
-
- benchmarks/setup.rb
|
116
|
-
- bin/console
|
117
107
|
- dry-logic.gemspec
|
118
|
-
- examples/basic.rb
|
119
108
|
- lib/dry-logic.rb
|
120
109
|
- lib/dry/logic.rb
|
121
110
|
- lib/dry/logic/appliable.rb
|
@@ -142,65 +131,14 @@ files:
|
|
142
131
|
- lib/dry/logic/rule/predicate.rb
|
143
132
|
- lib/dry/logic/rule_compiler.rb
|
144
133
|
- lib/dry/logic/version.rb
|
145
|
-
-
|
146
|
-
- spec/integration/rule_spec.rb
|
147
|
-
- spec/shared/predicates.rb
|
148
|
-
- spec/shared/rule.rb
|
149
|
-
- spec/spec_helper.rb
|
150
|
-
- spec/support/mutant.rb
|
151
|
-
- spec/unit/operations/and_spec.rb
|
152
|
-
- spec/unit/operations/attr_spec.rb
|
153
|
-
- spec/unit/operations/check_spec.rb
|
154
|
-
- spec/unit/operations/each_spec.rb
|
155
|
-
- spec/unit/operations/implication_spec.rb
|
156
|
-
- spec/unit/operations/key_spec.rb
|
157
|
-
- spec/unit/operations/negation_spec.rb
|
158
|
-
- spec/unit/operations/or_spec.rb
|
159
|
-
- spec/unit/operations/set_spec.rb
|
160
|
-
- spec/unit/operations/xor_spec.rb
|
161
|
-
- spec/unit/predicates/array_spec.rb
|
162
|
-
- spec/unit/predicates/attr_spec.rb
|
163
|
-
- spec/unit/predicates/bool_spec.rb
|
164
|
-
- spec/unit/predicates/case_spec.rb
|
165
|
-
- spec/unit/predicates/date_spec.rb
|
166
|
-
- spec/unit/predicates/date_time_spec.rb
|
167
|
-
- spec/unit/predicates/decimal_spec.rb
|
168
|
-
- spec/unit/predicates/empty_spec.rb
|
169
|
-
- spec/unit/predicates/eql_spec.rb
|
170
|
-
- spec/unit/predicates/even_spec.rb
|
171
|
-
- spec/unit/predicates/excluded_from_spec.rb
|
172
|
-
- spec/unit/predicates/excludes_spec.rb
|
173
|
-
- spec/unit/predicates/false_spec.rb
|
174
|
-
- spec/unit/predicates/filled_spec.rb
|
175
|
-
- spec/unit/predicates/float_spec.rb
|
176
|
-
- spec/unit/predicates/format_spec.rb
|
177
|
-
- spec/unit/predicates/gt_spec.rb
|
178
|
-
- spec/unit/predicates/gteq_spec.rb
|
179
|
-
- spec/unit/predicates/included_in_spec.rb
|
180
|
-
- spec/unit/predicates/includes_spec.rb
|
181
|
-
- spec/unit/predicates/int_spec.rb
|
182
|
-
- spec/unit/predicates/key_spec.rb
|
183
|
-
- spec/unit/predicates/lt_spec.rb
|
184
|
-
- spec/unit/predicates/lteq_spec.rb
|
185
|
-
- spec/unit/predicates/max_size_spec.rb
|
186
|
-
- spec/unit/predicates/min_size_spec.rb
|
187
|
-
- spec/unit/predicates/none_spec.rb
|
188
|
-
- spec/unit/predicates/not_eql_spec.rb
|
189
|
-
- spec/unit/predicates/number_spec.rb
|
190
|
-
- spec/unit/predicates/odd_spec.rb
|
191
|
-
- spec/unit/predicates/size_spec.rb
|
192
|
-
- spec/unit/predicates/str_spec.rb
|
193
|
-
- spec/unit/predicates/time_spec.rb
|
194
|
-
- spec/unit/predicates/true_spec.rb
|
195
|
-
- spec/unit/predicates/type_spec.rb
|
196
|
-
- spec/unit/predicates_spec.rb
|
197
|
-
- spec/unit/rule/predicate_spec.rb
|
198
|
-
- spec/unit/rule_compiler_spec.rb
|
199
|
-
- spec/unit/rule_spec.rb
|
200
|
-
homepage: https://github.com/dry-rb/dry-logic
|
134
|
+
homepage: https://dry-rb.org/gems/dry-logic
|
201
135
|
licenses:
|
202
136
|
- MIT
|
203
|
-
metadata:
|
137
|
+
metadata:
|
138
|
+
allowed_push_host: https://rubygems.org
|
139
|
+
changelog_uri: https://github.com/dry-rb/dry-logic/blob/master/CHANGELOG.md
|
140
|
+
source_code_uri: https://github.com/dry-rb/dry-logic
|
141
|
+
bug_tracker_uri: https://github.com/dry-rb/dry-logic/issues
|
204
142
|
post_install_message:
|
205
143
|
rdoc_options: []
|
206
144
|
require_paths:
|
@@ -209,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
147
|
requirements:
|
210
148
|
- - ">="
|
211
149
|
- !ruby/object:Gem::Version
|
212
|
-
version:
|
150
|
+
version: 2.4.0
|
213
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
152
|
requirements:
|
215
153
|
- - ">="
|
@@ -220,59 +158,4 @@ rubygems_version: 3.0.3
|
|
220
158
|
signing_key:
|
221
159
|
specification_version: 4
|
222
160
|
summary: Predicate logic with rule composition
|
223
|
-
test_files:
|
224
|
-
- spec/integration/result_spec.rb
|
225
|
-
- spec/integration/rule_spec.rb
|
226
|
-
- spec/shared/predicates.rb
|
227
|
-
- spec/shared/rule.rb
|
228
|
-
- spec/spec_helper.rb
|
229
|
-
- spec/support/mutant.rb
|
230
|
-
- spec/unit/operations/and_spec.rb
|
231
|
-
- spec/unit/operations/attr_spec.rb
|
232
|
-
- spec/unit/operations/check_spec.rb
|
233
|
-
- spec/unit/operations/each_spec.rb
|
234
|
-
- spec/unit/operations/implication_spec.rb
|
235
|
-
- spec/unit/operations/key_spec.rb
|
236
|
-
- spec/unit/operations/negation_spec.rb
|
237
|
-
- spec/unit/operations/or_spec.rb
|
238
|
-
- spec/unit/operations/set_spec.rb
|
239
|
-
- spec/unit/operations/xor_spec.rb
|
240
|
-
- spec/unit/predicates/array_spec.rb
|
241
|
-
- spec/unit/predicates/attr_spec.rb
|
242
|
-
- spec/unit/predicates/bool_spec.rb
|
243
|
-
- spec/unit/predicates/case_spec.rb
|
244
|
-
- spec/unit/predicates/date_spec.rb
|
245
|
-
- spec/unit/predicates/date_time_spec.rb
|
246
|
-
- spec/unit/predicates/decimal_spec.rb
|
247
|
-
- spec/unit/predicates/empty_spec.rb
|
248
|
-
- spec/unit/predicates/eql_spec.rb
|
249
|
-
- spec/unit/predicates/even_spec.rb
|
250
|
-
- spec/unit/predicates/excluded_from_spec.rb
|
251
|
-
- spec/unit/predicates/excludes_spec.rb
|
252
|
-
- spec/unit/predicates/false_spec.rb
|
253
|
-
- spec/unit/predicates/filled_spec.rb
|
254
|
-
- spec/unit/predicates/float_spec.rb
|
255
|
-
- spec/unit/predicates/format_spec.rb
|
256
|
-
- spec/unit/predicates/gt_spec.rb
|
257
|
-
- spec/unit/predicates/gteq_spec.rb
|
258
|
-
- spec/unit/predicates/included_in_spec.rb
|
259
|
-
- spec/unit/predicates/includes_spec.rb
|
260
|
-
- spec/unit/predicates/int_spec.rb
|
261
|
-
- spec/unit/predicates/key_spec.rb
|
262
|
-
- spec/unit/predicates/lt_spec.rb
|
263
|
-
- spec/unit/predicates/lteq_spec.rb
|
264
|
-
- spec/unit/predicates/max_size_spec.rb
|
265
|
-
- spec/unit/predicates/min_size_spec.rb
|
266
|
-
- spec/unit/predicates/none_spec.rb
|
267
|
-
- spec/unit/predicates/not_eql_spec.rb
|
268
|
-
- spec/unit/predicates/number_spec.rb
|
269
|
-
- spec/unit/predicates/odd_spec.rb
|
270
|
-
- spec/unit/predicates/size_spec.rb
|
271
|
-
- spec/unit/predicates/str_spec.rb
|
272
|
-
- spec/unit/predicates/time_spec.rb
|
273
|
-
- spec/unit/predicates/true_spec.rb
|
274
|
-
- spec/unit/predicates/type_spec.rb
|
275
|
-
- spec/unit/predicates_spec.rb
|
276
|
-
- spec/unit/rule/predicate_spec.rb
|
277
|
-
- spec/unit/rule_compiler_spec.rb
|
278
|
-
- spec/unit/rule_spec.rb
|
161
|
+
test_files: []
|