dry-logic 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/benchmarks/rule_application.rb +2 -0
- data/benchmarks/setup.rb +2 -0
- data/bin/console +1 -0
- data/dry-logic.gemspec +2 -0
- data/examples/basic.rb +2 -0
- 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 +2 -0
- data/lib/dry/logic/operations/and.rb +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +11 -0
- data/lib/dry/logic/result.rb +2 -0
- data/lib/dry/logic/rule.rb +2 -0
- data/lib/dry/logic/rule/interface.rb +2 -0
- 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
- data/spec/integration/result_spec.rb +2 -0
- data/spec/integration/rule_spec.rb +2 -0
- data/spec/shared/predicates.rb +2 -0
- data/spec/shared/rule.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/mutant.rb +2 -0
- data/spec/unit/operations/and_spec.rb +2 -0
- data/spec/unit/operations/attr_spec.rb +2 -0
- data/spec/unit/operations/check_spec.rb +2 -0
- data/spec/unit/operations/each_spec.rb +2 -0
- data/spec/unit/operations/implication_spec.rb +2 -0
- data/spec/unit/operations/key_spec.rb +2 -0
- data/spec/unit/operations/negation_spec.rb +2 -0
- data/spec/unit/operations/or_spec.rb +2 -0
- data/spec/unit/operations/set_spec.rb +2 -0
- data/spec/unit/operations/xor_spec.rb +2 -0
- data/spec/unit/predicates/array_spec.rb +2 -0
- data/spec/unit/predicates/attr_spec.rb +2 -0
- data/spec/unit/predicates/bool_spec.rb +3 -1
- data/spec/unit/predicates/case_spec.rb +2 -0
- data/spec/unit/predicates/date_spec.rb +2 -0
- data/spec/unit/predicates/date_time_spec.rb +3 -1
- data/spec/unit/predicates/decimal_spec.rb +3 -1
- data/spec/unit/predicates/empty_spec.rb +2 -0
- data/spec/unit/predicates/eql_spec.rb +2 -0
- data/spec/unit/predicates/even_spec.rb +2 -0
- data/spec/unit/predicates/excluded_from_spec.rb +2 -0
- data/spec/unit/predicates/excludes_spec.rb +2 -0
- data/spec/unit/predicates/false_spec.rb +3 -1
- data/spec/unit/predicates/filled_spec.rb +2 -0
- data/spec/unit/predicates/float_spec.rb +2 -0
- data/spec/unit/predicates/format_spec.rb +2 -0
- data/spec/unit/predicates/gt_spec.rb +2 -0
- data/spec/unit/predicates/gteq_spec.rb +2 -0
- data/spec/unit/predicates/included_in_spec.rb +2 -0
- data/spec/unit/predicates/int_spec.rb +2 -0
- data/spec/unit/predicates/key_spec.rb +2 -0
- data/spec/unit/predicates/lt_spec.rb +2 -0
- data/spec/unit/predicates/lteq_spec.rb +2 -0
- data/spec/unit/predicates/max_size_spec.rb +2 -0
- data/spec/unit/predicates/min_size_spec.rb +2 -0
- data/spec/unit/predicates/none_spec.rb +2 -0
- data/spec/unit/predicates/not_eql_spec.rb +2 -0
- data/spec/unit/predicates/number_spec.rb +2 -0
- data/spec/unit/predicates/odd_spec.rb +2 -0
- data/spec/unit/predicates/respond_to_spec.rb +31 -0
- data/spec/unit/predicates/size_spec.rb +2 -0
- data/spec/unit/predicates/str_spec.rb +2 -0
- data/spec/unit/predicates/time_spec.rb +3 -1
- data/spec/unit/predicates/true_spec.rb +3 -1
- data/spec/unit/predicates/type_spec.rb +2 -0
- data/spec/unit/predicates/uuid_v4_spec.rb +29 -0
- data/spec/unit/predicates_spec.rb +2 -0
- data/spec/unit/rule/predicate_spec.rb +2 -0
- data/spec/unit/rule_compiler_spec.rb +2 -0
- data/spec/unit/rule_spec.rb +4 -2
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '092fd6393e21a754ce653a7b24dfdcb2dacb719723b9e3bb6607c2ba73962bde'
|
4
|
+
data.tar.gz: 3b3a2407f0cdf5f4d17c3bae1888f32d8c63ca666cecc5d6266ee4604ce6f551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0ddca4a58b60a896077cc5c1d4b66e4c54470fb4182475e343bc90e3cdb6ec0e913784fc0c992c6e247532cfcdd50c2d47f48f467f443b71cab0f92fbf5d6da
|
7
|
+
data.tar.gz: a164d2b12242437c48d035e0cb139b1a24373d1d79f074d6b718fb81e7a6303f23cfc85c352fbfe8fdd9adf9602e44049d0bdcb15689d376b43a5b56fce549a6
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
|
+
# v1.0.1 2019-06-04 (yanked)
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
- `uuid_v4?` predicate (radar)
|
6
|
+
- `respond_to?` predicate (waiting-for-dev)
|
7
|
+
|
8
|
+
[Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-logic/compare/v1.0.0...v1.0.1)
|
9
|
+
|
10
|
+
This release was removed from rubygems because it broke dry-schema.
|
11
|
+
|
1
12
|
# v1.0.0 2019-04-23
|
2
13
|
|
3
|
-
Version bump to 1.0.0
|
14
|
+
* Version bump to `1.0.0` (flash-gordon)
|
4
15
|
|
5
16
|
[Compare v0.6.1...v1.0.0](https://github.com/dry-rb/dry-logic/compare/v0.6.1...v1.0.0)
|
6
17
|
|
data/CONTRIBUTING.md
CHANGED
@@ -6,11 +6,11 @@ If you found a bug, report an issue and describe what's the expected behavior ve
|
|
6
6
|
|
7
7
|
## Reporting feature requests
|
8
8
|
|
9
|
-
Report a feature request **only after discussing it first on [
|
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
10
|
|
11
11
|
## Reporting questions, support requests, ideas, concerns etc.
|
12
12
|
|
13
|
-
**PLEASE DON'T** - use [
|
13
|
+
**PLEASE DON'T** - use [discourse.dry-rb.org](https://discourse.dry-rb.org) instead.
|
14
14
|
|
15
15
|
# Pull Request Guidelines
|
16
16
|
|
@@ -26,4 +26,4 @@ Other requirements:
|
|
26
26
|
|
27
27
|
# Asking for help
|
28
28
|
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [
|
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
CHANGED
data/Rakefile
CHANGED
data/benchmarks/setup.rb
CHANGED
data/bin/console
CHANGED
data/dry-logic.gemspec
CHANGED
data/examples/basic.rb
CHANGED
data/lib/dry-logic.rb
CHANGED
data/lib/dry/logic.rb
CHANGED
data/lib/dry/logic/appliable.rb
CHANGED
data/lib/dry/logic/evaluator.rb
CHANGED
data/lib/dry/logic/operations.rb
CHANGED
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'
|
@@ -197,6 +199,15 @@ module Dry
|
|
197
199
|
pattern === input
|
198
200
|
end
|
199
201
|
|
202
|
+
def uuid_v4?(input)
|
203
|
+
uuid_v4_format = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
|
204
|
+
format?(uuid_v4_format, input)
|
205
|
+
end
|
206
|
+
|
207
|
+
def respond_to?(method, input)
|
208
|
+
input.respond_to?(method)
|
209
|
+
end
|
210
|
+
|
200
211
|
def predicate(name, &block)
|
201
212
|
define_singleton_method(name, &block)
|
202
213
|
end
|
data/lib/dry/logic/result.rb
CHANGED
data/lib/dry/logic/rule.rb
CHANGED
data/lib/dry/logic/version.rb
CHANGED
data/spec/shared/predicates.rb
CHANGED
data/spec/shared/rule.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/support/mutant.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/logic/predicates'
|
2
4
|
|
3
5
|
RSpec.describe Dry::Logic::Predicates do
|
4
6
|
describe '#bool?' do
|
5
7
|
let(:predicate_name) { :bool? }
|
6
8
|
|
7
|
-
context 'when value is a
|
9
|
+
context 'when value is a boolean' do
|
8
10
|
let(:arguments_list) do
|
9
11
|
[[true], [false]]
|
10
12
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/logic/predicates'
|
2
4
|
|
3
5
|
RSpec.describe Dry::Logic::Predicates do
|
4
6
|
describe '#date_time?' do
|
5
7
|
let(:predicate_name) { :date_time? }
|
6
8
|
|
7
|
-
context 'when value is a
|
9
|
+
context 'when value is a datetime' do
|
8
10
|
let(:arguments_list) do
|
9
11
|
[[DateTime.now]]
|
10
12
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/logic/predicates'
|
2
4
|
|
3
5
|
RSpec.describe Dry::Logic::Predicates do
|
4
6
|
describe '#decimal?' do
|
5
7
|
let(:predicate_name) { :decimal? }
|
6
8
|
|
7
|
-
context 'when value is a
|
9
|
+
context 'when value is a decimal' do
|
8
10
|
let(:arguments_list) do
|
9
11
|
[[1.2.to_d]]
|
10
12
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/logic/predicates'
|
2
4
|
|
3
5
|
RSpec.describe Dry::Logic::Predicates do
|
4
6
|
describe '#false?' do
|
5
7
|
let(:predicate_name) { :false? }
|
6
8
|
|
7
|
-
context 'when value is
|
9
|
+
context 'when value is false' do
|
8
10
|
let(:arguments_list) do
|
9
11
|
[[false]]
|
10
12
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry/logic/predicates'
|
4
|
+
|
5
|
+
RSpec.describe Dry::Logic::Predicates do
|
6
|
+
describe '#respond_to?' do
|
7
|
+
let(:predicate_name) { :respond_to? }
|
8
|
+
|
9
|
+
context 'when value responds to method' do
|
10
|
+
let(:arguments_list) do
|
11
|
+
[
|
12
|
+
[:method, Object],
|
13
|
+
[:new, Hash]
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
it_behaves_like 'a passing predicate'
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when value does not respond to method' do
|
21
|
+
let(:arguments_list) do
|
22
|
+
[
|
23
|
+
[:foo, Object],
|
24
|
+
[:bar, Hash]
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
it_behaves_like 'a failing predicate'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/logic/predicates'
|
2
4
|
|
3
5
|
RSpec.describe Dry::Logic::Predicates do
|
4
6
|
describe '#time?' do
|
5
7
|
let(:predicate_name) { :time? }
|
6
8
|
|
7
|
-
context 'when value is a
|
9
|
+
context 'when value is a time' do
|
8
10
|
let(:arguments_list) do
|
9
11
|
[[Time.now]]
|
10
12
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/logic/predicates'
|
2
4
|
|
3
5
|
RSpec.describe Dry::Logic::Predicates do
|
4
6
|
describe '#true?' do
|
5
7
|
let(:predicate_name) { :true? }
|
6
8
|
|
7
|
-
context 'when value is
|
9
|
+
context 'when value is true' do
|
8
10
|
let(:arguments_list) do
|
9
11
|
[[true]]
|
10
12
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry/logic/predicates'
|
4
|
+
|
5
|
+
RSpec.describe Dry::Logic::Predicates do
|
6
|
+
describe '#uuid_v4?' do
|
7
|
+
let(:predicate_name) { :uuid_v4? }
|
8
|
+
|
9
|
+
context 'when value is a valid V4 UUID' do
|
10
|
+
let(:arguments_list) do
|
11
|
+
[['f2d26c57-e07c-4416-a749-57e937930e04']]
|
12
|
+
end
|
13
|
+
|
14
|
+
it_behaves_like 'a passing predicate'
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with value is not a valid V4 UUID' do
|
18
|
+
let(:arguments_list) do
|
19
|
+
[
|
20
|
+
['f2d26c57-e07c-3416-a749-57e937930e04'], # wrong version number (3, not 4)
|
21
|
+
['20633928-6a07-11e9-a923-1681be663d3e'], # UUID V1
|
22
|
+
['not-a-uuid-at-all']
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
it_behaves_like 'a failing predicate'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/unit/rule_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Dry::Logic::Rule do
|
2
4
|
subject(:rule) { Rule.build(predicate, options) }
|
3
5
|
|
@@ -178,8 +180,8 @@ RSpec.describe Dry::Logic::Rule do
|
|
178
180
|
end
|
179
181
|
|
180
182
|
describe 'arbitrary arity' do
|
181
|
-
let(:arity) { rand(20) }
|
182
|
-
let(:curried) {
|
183
|
+
let(:arity) { rand(1..20) }
|
184
|
+
let(:curried) { rand(arity) }
|
183
185
|
|
184
186
|
let(:options) { { args: [1] * curried, arity: arity } }
|
185
187
|
let(:predicate) { double(:predicate) }
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -188,11 +188,13 @@ files:
|
|
188
188
|
- spec/unit/predicates/not_eql_spec.rb
|
189
189
|
- spec/unit/predicates/number_spec.rb
|
190
190
|
- spec/unit/predicates/odd_spec.rb
|
191
|
+
- spec/unit/predicates/respond_to_spec.rb
|
191
192
|
- spec/unit/predicates/size_spec.rb
|
192
193
|
- spec/unit/predicates/str_spec.rb
|
193
194
|
- spec/unit/predicates/time_spec.rb
|
194
195
|
- spec/unit/predicates/true_spec.rb
|
195
196
|
- spec/unit/predicates/type_spec.rb
|
197
|
+
- spec/unit/predicates/uuid_v4_spec.rb
|
196
198
|
- spec/unit/predicates_spec.rb
|
197
199
|
- spec/unit/rule/predicate_spec.rb
|
198
200
|
- spec/unit/rule_compiler_spec.rb
|
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
218
|
- !ruby/object:Gem::Version
|
217
219
|
version: '0'
|
218
220
|
requirements: []
|
219
|
-
rubygems_version: 3.0.
|
221
|
+
rubygems_version: 3.0.1
|
220
222
|
signing_key:
|
221
223
|
specification_version: 4
|
222
224
|
summary: Predicate logic with rule composition
|
@@ -267,11 +269,13 @@ test_files:
|
|
267
269
|
- spec/unit/predicates/not_eql_spec.rb
|
268
270
|
- spec/unit/predicates/number_spec.rb
|
269
271
|
- spec/unit/predicates/odd_spec.rb
|
272
|
+
- spec/unit/predicates/respond_to_spec.rb
|
270
273
|
- spec/unit/predicates/size_spec.rb
|
271
274
|
- spec/unit/predicates/str_spec.rb
|
272
275
|
- spec/unit/predicates/time_spec.rb
|
273
276
|
- spec/unit/predicates/true_spec.rb
|
274
277
|
- spec/unit/predicates/type_spec.rb
|
278
|
+
- spec/unit/predicates/uuid_v4_spec.rb
|
275
279
|
- spec/unit/predicates_spec.rb
|
276
280
|
- spec/unit/rule/predicate_spec.rb
|
277
281
|
- spec/unit/rule_compiler_spec.rb
|