dry-logic 1.0.2 → 1.0.8
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 +129 -26
- data/LICENSE +1 -1
- data/README.md +12 -14
- data/dry-logic.gemspec +27 -14
- 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 +6 -6
- data/lib/dry/logic/operations/and.rb +4 -4
- 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 +4 -4
- 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 +5 -5
- 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 +60 -28
- data/lib/dry/logic/result.rb +2 -2
- data/lib/dry/logic/rule.rb +11 -11
- data/lib/dry/logic/rule/interface.rb +32 -37
- 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 +12 -133
- data/.codeclimate.yml +0 -15
- data/.gitignore +0 -9
- data/.rspec +0 -3
- data/.travis.yml +0 -31
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -15
- data/Rakefile +0 -14
- data/benchmarks/rule_application.rb +0 -30
- data/benchmarks/setup.rb +0 -13
- data/bin/console +0 -11
- data/examples/basic.rb +0 -16
- data/spec/integration/result_spec.rb +0 -61
- data/spec/integration/rule_spec.rb +0 -55
- data/spec/shared/predicates.rb +0 -59
- data/spec/shared/rule.rb +0 -74
- data/spec/spec_helper.rb +0 -36
- data/spec/support/mutant.rb +0 -11
- data/spec/unit/operations/and_spec.rb +0 -70
- data/spec/unit/operations/attr_spec.rb +0 -29
- data/spec/unit/operations/check_spec.rb +0 -51
- data/spec/unit/operations/each_spec.rb +0 -49
- data/spec/unit/operations/implication_spec.rb +0 -32
- data/spec/unit/operations/key_spec.rb +0 -135
- data/spec/unit/operations/negation_spec.rb +0 -51
- data/spec/unit/operations/or_spec.rb +0 -75
- data/spec/unit/operations/set_spec.rb +0 -43
- data/spec/unit/operations/xor_spec.rb +0 -63
- data/spec/unit/predicates/array_spec.rb +0 -43
- data/spec/unit/predicates/attr_spec.rb +0 -31
- data/spec/unit/predicates/bool_spec.rb +0 -36
- data/spec/unit/predicates/case_spec.rb +0 -35
- data/spec/unit/predicates/date_spec.rb +0 -33
- data/spec/unit/predicates/date_time_spec.rb +0 -33
- data/spec/unit/predicates/decimal_spec.rb +0 -34
- data/spec/unit/predicates/empty_spec.rb +0 -40
- data/spec/unit/predicates/eql_spec.rb +0 -23
- data/spec/unit/predicates/even_spec.rb +0 -33
- data/spec/unit/predicates/excluded_from_spec.rb +0 -37
- data/spec/unit/predicates/excludes_spec.rb +0 -58
- data/spec/unit/predicates/false_spec.rb +0 -37
- data/spec/unit/predicates/filled_spec.rb +0 -40
- data/spec/unit/predicates/float_spec.rb +0 -33
- data/spec/unit/predicates/format_spec.rb +0 -23
- data/spec/unit/predicates/gt_spec.rb +0 -42
- data/spec/unit/predicates/gteq_spec.rb +0 -42
- data/spec/unit/predicates/included_in_spec.rb +0 -37
- data/spec/unit/predicates/includes_spec.rb +0 -24
- data/spec/unit/predicates/int_spec.rb +0 -36
- data/spec/unit/predicates/key_spec.rb +0 -31
- data/spec/unit/predicates/lt_spec.rb +0 -42
- data/spec/unit/predicates/lteq_spec.rb +0 -42
- data/spec/unit/predicates/max_size_spec.rb +0 -51
- data/spec/unit/predicates/min_size_spec.rb +0 -51
- data/spec/unit/predicates/none_spec.rb +0 -30
- data/spec/unit/predicates/not_eql_spec.rb +0 -23
- data/spec/unit/predicates/number_spec.rb +0 -39
- data/spec/unit/predicates/odd_spec.rb +0 -33
- data/spec/unit/predicates/respond_to_spec.rb +0 -31
- data/spec/unit/predicates/size_spec.rb +0 -57
- data/spec/unit/predicates/str_spec.rb +0 -34
- data/spec/unit/predicates/time_spec.rb +0 -33
- data/spec/unit/predicates/true_spec.rb +0 -37
- data/spec/unit/predicates/type_spec.rb +0 -37
- data/spec/unit/predicates/uuid_v4_spec.rb +0 -29
- data/spec/unit/predicates_spec.rb +0 -25
- data/spec/unit/rule/predicate_spec.rb +0 -55
- data/spec/unit/rule_compiler_spec.rb +0 -129
- data/spec/unit/rule_spec.rb +0 -213
@@ -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.8
|
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-09-28 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,67 +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/respond_to_spec.rb
|
192
|
-
- spec/unit/predicates/size_spec.rb
|
193
|
-
- spec/unit/predicates/str_spec.rb
|
194
|
-
- spec/unit/predicates/time_spec.rb
|
195
|
-
- spec/unit/predicates/true_spec.rb
|
196
|
-
- spec/unit/predicates/type_spec.rb
|
197
|
-
- spec/unit/predicates/uuid_v4_spec.rb
|
198
|
-
- spec/unit/predicates_spec.rb
|
199
|
-
- spec/unit/rule/predicate_spec.rb
|
200
|
-
- spec/unit/rule_compiler_spec.rb
|
201
|
-
- spec/unit/rule_spec.rb
|
202
|
-
homepage: https://github.com/dry-rb/dry-logic
|
134
|
+
homepage: https://dry-rb.org/gems/dry-logic
|
203
135
|
licenses:
|
204
136
|
- MIT
|
205
|
-
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
|
206
142
|
post_install_message:
|
207
143
|
rdoc_options: []
|
208
144
|
require_paths:
|
@@ -211,72 +147,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
147
|
requirements:
|
212
148
|
- - ">="
|
213
149
|
- !ruby/object:Gem::Version
|
214
|
-
version:
|
150
|
+
version: 2.4.0
|
215
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
152
|
requirements:
|
217
153
|
- - ">="
|
218
154
|
- !ruby/object:Gem::Version
|
219
155
|
version: '0'
|
220
156
|
requirements: []
|
221
|
-
rubygems_version: 3.0.
|
157
|
+
rubygems_version: 3.0.3
|
222
158
|
signing_key:
|
223
159
|
specification_version: 4
|
224
160
|
summary: Predicate logic with rule composition
|
225
|
-
test_files:
|
226
|
-
- spec/integration/result_spec.rb
|
227
|
-
- spec/integration/rule_spec.rb
|
228
|
-
- spec/shared/predicates.rb
|
229
|
-
- spec/shared/rule.rb
|
230
|
-
- spec/spec_helper.rb
|
231
|
-
- spec/support/mutant.rb
|
232
|
-
- spec/unit/operations/and_spec.rb
|
233
|
-
- spec/unit/operations/attr_spec.rb
|
234
|
-
- spec/unit/operations/check_spec.rb
|
235
|
-
- spec/unit/operations/each_spec.rb
|
236
|
-
- spec/unit/operations/implication_spec.rb
|
237
|
-
- spec/unit/operations/key_spec.rb
|
238
|
-
- spec/unit/operations/negation_spec.rb
|
239
|
-
- spec/unit/operations/or_spec.rb
|
240
|
-
- spec/unit/operations/set_spec.rb
|
241
|
-
- spec/unit/operations/xor_spec.rb
|
242
|
-
- spec/unit/predicates/array_spec.rb
|
243
|
-
- spec/unit/predicates/attr_spec.rb
|
244
|
-
- spec/unit/predicates/bool_spec.rb
|
245
|
-
- spec/unit/predicates/case_spec.rb
|
246
|
-
- spec/unit/predicates/date_spec.rb
|
247
|
-
- spec/unit/predicates/date_time_spec.rb
|
248
|
-
- spec/unit/predicates/decimal_spec.rb
|
249
|
-
- spec/unit/predicates/empty_spec.rb
|
250
|
-
- spec/unit/predicates/eql_spec.rb
|
251
|
-
- spec/unit/predicates/even_spec.rb
|
252
|
-
- spec/unit/predicates/excluded_from_spec.rb
|
253
|
-
- spec/unit/predicates/excludes_spec.rb
|
254
|
-
- spec/unit/predicates/false_spec.rb
|
255
|
-
- spec/unit/predicates/filled_spec.rb
|
256
|
-
- spec/unit/predicates/float_spec.rb
|
257
|
-
- spec/unit/predicates/format_spec.rb
|
258
|
-
- spec/unit/predicates/gt_spec.rb
|
259
|
-
- spec/unit/predicates/gteq_spec.rb
|
260
|
-
- spec/unit/predicates/included_in_spec.rb
|
261
|
-
- spec/unit/predicates/includes_spec.rb
|
262
|
-
- spec/unit/predicates/int_spec.rb
|
263
|
-
- spec/unit/predicates/key_spec.rb
|
264
|
-
- spec/unit/predicates/lt_spec.rb
|
265
|
-
- spec/unit/predicates/lteq_spec.rb
|
266
|
-
- spec/unit/predicates/max_size_spec.rb
|
267
|
-
- spec/unit/predicates/min_size_spec.rb
|
268
|
-
- spec/unit/predicates/none_spec.rb
|
269
|
-
- spec/unit/predicates/not_eql_spec.rb
|
270
|
-
- spec/unit/predicates/number_spec.rb
|
271
|
-
- spec/unit/predicates/odd_spec.rb
|
272
|
-
- spec/unit/predicates/respond_to_spec.rb
|
273
|
-
- spec/unit/predicates/size_spec.rb
|
274
|
-
- spec/unit/predicates/str_spec.rb
|
275
|
-
- spec/unit/predicates/time_spec.rb
|
276
|
-
- spec/unit/predicates/true_spec.rb
|
277
|
-
- spec/unit/predicates/type_spec.rb
|
278
|
-
- spec/unit/predicates/uuid_v4_spec.rb
|
279
|
-
- spec/unit/predicates_spec.rb
|
280
|
-
- spec/unit/rule/predicate_spec.rb
|
281
|
-
- spec/unit/rule_compiler_spec.rb
|
282
|
-
- spec/unit/rule_spec.rb
|
161
|
+
test_files: []
|
data/.codeclimate.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
version: "2"
|
2
|
-
|
3
|
-
prepare:
|
4
|
-
fetch:
|
5
|
-
- url: "https://raw.githubusercontent.com/dry-rb/devtools/master/.rubocop.yml"
|
6
|
-
path: ".rubocop.yml"
|
7
|
-
|
8
|
-
exclude_patterns:
|
9
|
-
- "benchmarks/"
|
10
|
-
- "examples/"
|
11
|
-
- "spec/"
|
12
|
-
|
13
|
-
plugins:
|
14
|
-
rubocop:
|
15
|
-
enabled: true
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
bundler_args: --without benchmarks tools
|
4
|
-
before_script:
|
5
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
6
|
-
- chmod +x ./cc-test-reporter
|
7
|
-
- ./cc-test-reporter before-build
|
8
|
-
after_script:
|
9
|
-
- "[ -d coverage ] && ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
10
|
-
script:
|
11
|
-
- bundle exec rake
|
12
|
-
rvm:
|
13
|
-
- 2.6.3
|
14
|
-
- 2.5.5
|
15
|
-
- 2.4.6
|
16
|
-
- jruby-9.2.7.0
|
17
|
-
- truffleruby
|
18
|
-
env:
|
19
|
-
global:
|
20
|
-
- COVERAGE=true
|
21
|
-
matrix:
|
22
|
-
allow_failures:
|
23
|
-
- rvm: truffleruby
|
24
|
-
notifications:
|
25
|
-
email: false
|
26
|
-
webhooks:
|
27
|
-
urls:
|
28
|
-
- https://dry-rb.zulipchat.com/api/v1/external/travis?api_key=SY8LLz6fShd4TJeLDXEdT0eBEgRqT2lv&stream=notifications&topic=ci
|
29
|
-
on_success: change # options: [always|never|change] default: always
|
30
|
-
on_failure: always # options: [always|never|change] default: always
|
31
|
-
on_start: false # default: false
|
data/CONTRIBUTING.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Issue Guidelines
|
2
|
-
|
3
|
-
## Reporting bugs
|
4
|
-
|
5
|
-
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
-
|
7
|
-
## Reporting feature requests
|
8
|
-
|
9
|
-
Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
|
10
|
-
|
11
|
-
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
-
|
13
|
-
**PLEASE DON'T** - use [discourse.dry-rb.org](https://discourse.dry-rb.org) instead.
|
14
|
-
|
15
|
-
# Pull Request Guidelines
|
16
|
-
|
17
|
-
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
-
|
19
|
-
Other requirements:
|
20
|
-
|
21
|
-
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
-
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
-
3) Add API documentation if it's a new feature
|
24
|
-
4) Update API documentation if it changes an existing feature
|
25
|
-
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
-
|
27
|
-
# Asking for help
|
28
|
-
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
|
data/Gemfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
gemspec
|
6
|
-
|
7
|
-
group :test do
|
8
|
-
gem 'simplecov', require: false, platform: :mri
|
9
|
-
end
|
10
|
-
|
11
|
-
group :tools do
|
12
|
-
gem 'pry-byebug', platform: :mri
|
13
|
-
gem 'benchmark-ips', platform: :mri
|
14
|
-
gem 'hotch', platform: :mri
|
15
|
-
end
|
data/Rakefile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/gem_tasks'
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
7
|
-
|
8
|
-
require 'rspec/core'
|
9
|
-
require 'rspec/core/rake_task'
|
10
|
-
|
11
|
-
task default: :spec
|
12
|
-
|
13
|
-
desc 'Run all specs in spec directory'
|
14
|
-
RSpec::Core::RakeTask.new(:spec)
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'setup'
|
4
|
-
|
5
|
-
unless Dry::Logic::Rule.respond_to?(:build)
|
6
|
-
Dry::Logic::Rule.singleton_class.alias_method(:build, :new)
|
7
|
-
end
|
8
|
-
|
9
|
-
predicates = Dry::Logic::Predicates
|
10
|
-
|
11
|
-
type_check = Dry::Logic::Rule.build(predicates[:type?]).curry(Integer)
|
12
|
-
int_check = Dry::Logic::Rule.build(predicates[:int?])
|
13
|
-
key_check = Dry::Logic::Rule.build(predicates[:key?]).curry(:user)
|
14
|
-
with_user = { user: {} }
|
15
|
-
without_user = {}
|
16
|
-
|
17
|
-
comparison = Dry::Logic::Rule.build(predicates[:gteq?]).curry(18)
|
18
|
-
|
19
|
-
Benchmark.ips do |x|
|
20
|
-
x.report("type check - success") { type_check.(0) }
|
21
|
-
x.report("type check - failure") { type_check.('0') }
|
22
|
-
x.report("int check - success") { int_check.(0) }
|
23
|
-
x.report("int check - failure") { int_check.('0') }
|
24
|
-
x.report("key check - success") { key_check.(with_user) }
|
25
|
-
x.report("key check - failure") { key_check.(without_user) }
|
26
|
-
x.report("comparison - success") { comparison.(20) }
|
27
|
-
x.report("comparison - failure") { comparison.(17) }
|
28
|
-
|
29
|
-
x.compare!
|
30
|
-
end
|
data/benchmarks/setup.rb
DELETED
data/bin/console
DELETED
data/examples/basic.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic'
|
4
|
-
require 'dry/logic/predicates'
|
5
|
-
|
6
|
-
include Dry::Logic
|
7
|
-
|
8
|
-
user_present = Rule::Predicate.build(Predicates[:key?]).curry(:user)
|
9
|
-
|
10
|
-
has_min_age = Operations::Key.new(Rule::Predicate.build(Predicates[:gt?]).curry(18), name: [:user, :age])
|
11
|
-
|
12
|
-
user_rule = user_present & has_min_age
|
13
|
-
|
14
|
-
puts user_rule.(user: { age: 19 }).success?
|
15
|
-
|
16
|
-
puts user_rule.(user: { age: 18 }).success?
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Result do
|
4
|
-
include_context 'predicates'
|
5
|
-
|
6
|
-
describe '#to_s' do
|
7
|
-
shared_examples_for 'string representation' do
|
8
|
-
it 'returns string representation' do
|
9
|
-
expect(rule.(input).to_s).to eql(output)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'with a predicate' do
|
14
|
-
let(:rule) { Rule::Predicate.build(gt?, args: [18]) }
|
15
|
-
let(:input) { 17 }
|
16
|
-
let(:output) { 'gt?(18, 17)' }
|
17
|
-
|
18
|
-
it_behaves_like 'string representation'
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with AND operation' do
|
22
|
-
let(:rule) { Rule::Predicate.build(array?).and(Rule::Predicate.build(empty?)) }
|
23
|
-
let(:input) { '' }
|
24
|
-
let(:output) { 'array?("") AND empty?("")' }
|
25
|
-
|
26
|
-
it_behaves_like 'string representation'
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with OR operation' do
|
30
|
-
let(:rule) { Rule::Predicate.build(array?).or(Rule::Predicate.build(empty?)) }
|
31
|
-
let(:input) { 123 }
|
32
|
-
let(:output) { 'array?(123) OR empty?(123)' }
|
33
|
-
|
34
|
-
it_behaves_like 'string representation'
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'with XOR operation' do
|
38
|
-
let(:rule) { Rule::Predicate.build(array?).xor(Rule::Predicate.build(empty?)) }
|
39
|
-
let(:input) { [] }
|
40
|
-
let(:output) { 'array?([]) XOR empty?([])' }
|
41
|
-
|
42
|
-
it_behaves_like 'string representation'
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'with THEN operation' do
|
46
|
-
let(:rule) { Rule::Predicate.build(array?).then(Rule::Predicate.build(empty?)) }
|
47
|
-
let(:input) { [1, 2, 3] }
|
48
|
-
let(:output) { 'empty?([1, 2, 3])' }
|
49
|
-
|
50
|
-
it_behaves_like 'string representation'
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'with NOT operation' do
|
54
|
-
let(:rule) { Operations::Negation.new(Rule::Predicate.build(array?)) }
|
55
|
-
let(:input) { 'foo' }
|
56
|
-
let(:output) { 'not(array?("foo"))' }
|
57
|
-
|
58
|
-
it_behaves_like 'string representation'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|