dry-logic 1.0.5 → 1.1.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 +122 -26
- data/LICENSE +1 -1
- data/README.md +12 -14
- data/dry-logic.gemspec +26 -20
- 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 +4 -3
- 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 +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 +32 -7
- data/lib/dry/logic/result.rb +2 -2
- data/lib/dry/logic/rule.rb +8 -8
- 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 +17 -166
- data/.codeclimate.yml +0 -12
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
- data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -34
- data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
- data/.github/workflows/ci.yml +0 -70
- data/.github/workflows/docsite.yml +0 -34
- data/.github/workflows/sync_configs.yml +0 -34
- data/.gitignore +0 -9
- data/.rspec +0 -4
- data/.rubocop.yml +0 -89
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -16
- data/Rakefile +0 -14
- data/benchmarks/rule_application.rb +0 -30
- data/benchmarks/setup.rb +0 -13
- data/bin/console +0 -11
- data/docsite/source/index.html.md +0 -54
- data/docsite/source/operations.html.md +0 -62
- data/docsite/source/predicates.html.md +0 -102
- 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 -30
- 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/bytesize_spec.rb +0 -48
- 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 -31
- data/spec/unit/predicates/gt_spec.rb +0 -42
- data/spec/unit/predicates/gteq_spec.rb +0 -42
- data/spec/unit/predicates/hash_spec.rb +0 -40
- 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_bytesize_spec.rb +0 -39
- data/spec/unit/predicates/max_size_spec.rb +0 -51
- data/spec/unit/predicates/min_bytesize_spec.rb +0 -39
- 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,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#excludes?' do
|
7
|
-
let(:predicate_name) { :excludes? }
|
8
|
-
|
9
|
-
context 'with input excludes value' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[
|
12
|
-
['Jack', ['Jill', 'John']],
|
13
|
-
[0, 1..2],
|
14
|
-
[3, 1..2],
|
15
|
-
['foo', 'Hello World'],
|
16
|
-
[:foo, { bar: 0 }],
|
17
|
-
[true, [nil, false]]
|
18
|
-
]
|
19
|
-
end
|
20
|
-
|
21
|
-
it_behaves_like 'a passing predicate'
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with input of invalid type' do
|
25
|
-
let(:arguments_list) do
|
26
|
-
[
|
27
|
-
[2, 1],
|
28
|
-
[1, nil],
|
29
|
-
["foo", 1],
|
30
|
-
[1, "foo"],
|
31
|
-
[1..2, "foo"],
|
32
|
-
["foo", 1..2],
|
33
|
-
[:key, "foo"]
|
34
|
-
]
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like 'a passing predicate'
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when input includes value' do
|
41
|
-
let(:arguments_list) do
|
42
|
-
[
|
43
|
-
['Jill', ['Jill', 'John']],
|
44
|
-
['John', ['Jill', 'John']],
|
45
|
-
[1, 1..2],
|
46
|
-
[2, 1..2],
|
47
|
-
['Hello', 'Hello World'],
|
48
|
-
['World', 'Hello World'],
|
49
|
-
[:bar, { bar: 0 }],
|
50
|
-
[nil, [nil, false]],
|
51
|
-
[false, [nil, false]]
|
52
|
-
]
|
53
|
-
end
|
54
|
-
|
55
|
-
it_behaves_like 'a failing predicate'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#false?' do
|
7
|
-
let(:predicate_name) { :false? }
|
8
|
-
|
9
|
-
context 'when value is false' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[[false]]
|
12
|
-
end
|
13
|
-
|
14
|
-
it_behaves_like 'a passing predicate'
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'when value is not false' do
|
18
|
-
let(:arguments_list) do
|
19
|
-
[
|
20
|
-
[true],
|
21
|
-
[''],
|
22
|
-
[[]],
|
23
|
-
[{}],
|
24
|
-
[nil],
|
25
|
-
[:symbol],
|
26
|
-
[String],
|
27
|
-
[1],
|
28
|
-
[0],
|
29
|
-
['true'],
|
30
|
-
['false']
|
31
|
-
]
|
32
|
-
end
|
33
|
-
|
34
|
-
it_behaves_like 'a failing predicate'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#filled?' do
|
7
|
-
let(:predicate_name) { :filled? }
|
8
|
-
|
9
|
-
context 'when value is filled' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[
|
12
|
-
['Jill'],
|
13
|
-
[[1, 2, 3]],
|
14
|
-
[{ name: 'John' }],
|
15
|
-
[true],
|
16
|
-
[false],
|
17
|
-
['1'],
|
18
|
-
['0'],
|
19
|
-
[:symbol],
|
20
|
-
[String]
|
21
|
-
]
|
22
|
-
end
|
23
|
-
|
24
|
-
it_behaves_like 'a passing predicate'
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'with value is not filled' do
|
28
|
-
let(:arguments_list) do
|
29
|
-
[
|
30
|
-
[''],
|
31
|
-
[[]],
|
32
|
-
[{}],
|
33
|
-
[nil]
|
34
|
-
]
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like 'a failing predicate'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#float?' do
|
7
|
-
let(:predicate_name) { :float? }
|
8
|
-
|
9
|
-
context 'when value is a float' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[[1.0]]
|
12
|
-
end
|
13
|
-
|
14
|
-
it_behaves_like 'a passing predicate'
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'with value is not an integer' do
|
18
|
-
let(:arguments_list) do
|
19
|
-
[
|
20
|
-
[''],
|
21
|
-
[[]],
|
22
|
-
[{}],
|
23
|
-
[nil],
|
24
|
-
[:symbol],
|
25
|
-
[String],
|
26
|
-
[1]
|
27
|
-
]
|
28
|
-
end
|
29
|
-
|
30
|
-
it_behaves_like 'a failing predicate'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates, '#format?' do
|
6
|
-
let(:predicate_name) { :format? }
|
7
|
-
|
8
|
-
context 'when value matches provided regexp' do
|
9
|
-
let(:arguments_list) do
|
10
|
-
[[/^F/, 'Foo']]
|
11
|
-
end
|
12
|
-
|
13
|
-
it_behaves_like 'a passing predicate'
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when value does not match provided regexp' do
|
17
|
-
let(:arguments_list) do
|
18
|
-
[[/^F/, 'Bar']]
|
19
|
-
end
|
20
|
-
|
21
|
-
it_behaves_like 'a failing predicate'
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when input is nil' do
|
25
|
-
let(:arguments_list) do
|
26
|
-
[[/^F/, nil]]
|
27
|
-
end
|
28
|
-
|
29
|
-
it_behaves_like 'a failing predicate'
|
30
|
-
end
|
31
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#gt?' do
|
7
|
-
let(:predicate_name) { :gt? }
|
8
|
-
|
9
|
-
context 'when value is greater than n' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[
|
12
|
-
[13, 14],
|
13
|
-
[13.37, 13.38]
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
it_behaves_like 'a passing predicate'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when value is equal to n' do
|
21
|
-
let(:arguments_list) do
|
22
|
-
[
|
23
|
-
[13, 13],
|
24
|
-
[13.37, 13.37]
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
it_behaves_like 'a failing predicate'
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with value is less than n' do
|
32
|
-
let(:arguments_list) do
|
33
|
-
[
|
34
|
-
[13, 12],
|
35
|
-
[13.37, 13.36]
|
36
|
-
]
|
37
|
-
end
|
38
|
-
|
39
|
-
it_behaves_like 'a failing predicate'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#gteq?' do
|
7
|
-
let(:predicate_name) { :gteq? }
|
8
|
-
|
9
|
-
context 'when value is greater than n' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[
|
12
|
-
[13, 14],
|
13
|
-
[13.37, 13.38]
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
it_behaves_like 'a passing predicate'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when value is equal to n' do
|
21
|
-
let(:arguments_list) do
|
22
|
-
[
|
23
|
-
[13, 13],
|
24
|
-
[13.37, 13.37]
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
it_behaves_like 'a passing predicate'
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with value is less than n' do
|
32
|
-
let(:arguments_list) do
|
33
|
-
[
|
34
|
-
[13, 12],
|
35
|
-
[13.37, 13.36]
|
36
|
-
]
|
37
|
-
end
|
38
|
-
|
39
|
-
it_behaves_like 'a failing predicate'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#hash?' do
|
7
|
-
let(:predicate_name) { :hash? }
|
8
|
-
|
9
|
-
context 'when value is a hash' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[
|
12
|
-
[{}],
|
13
|
-
[foo: :bar],
|
14
|
-
[Hash.new]
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
it_behaves_like 'a passing predicate'
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when value is not a hash' do
|
22
|
-
let(:arguments_list) do
|
23
|
-
[
|
24
|
-
[''],
|
25
|
-
[[]],
|
26
|
-
[nil],
|
27
|
-
[:symbol],
|
28
|
-
[String],
|
29
|
-
[1],
|
30
|
-
[1.0],
|
31
|
-
[true],
|
32
|
-
[Array.new],
|
33
|
-
[Hash]
|
34
|
-
]
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like 'a failing predicate'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#included_in?' do
|
7
|
-
let(:predicate_name) { :included_in? }
|
8
|
-
|
9
|
-
context 'when value is present in list' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[
|
12
|
-
[['Jill', 'John'], 'Jill'],
|
13
|
-
[['Jill', 'John'], 'John'],
|
14
|
-
[1..2, 1],
|
15
|
-
[1..2, 2],
|
16
|
-
[[nil, false], nil],
|
17
|
-
[[nil, false], false]
|
18
|
-
]
|
19
|
-
end
|
20
|
-
|
21
|
-
it_behaves_like 'a passing predicate'
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with value is not present in list' do
|
25
|
-
let(:arguments_list) do
|
26
|
-
[
|
27
|
-
[['Jill', 'John'], 'Jack'],
|
28
|
-
[1..2, 0],
|
29
|
-
[1..2, 3],
|
30
|
-
[[nil, false], true]
|
31
|
-
]
|
32
|
-
end
|
33
|
-
|
34
|
-
it_behaves_like 'a failing predicate'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates, '#is?' do
|
4
|
-
let(:predicate_name) { :is? }
|
5
|
-
let(:one) { Object.new }
|
6
|
-
let(:two) { Object.new }
|
7
|
-
|
8
|
-
context 'when value is equal to the arg' do
|
9
|
-
let(:arguments_list) do
|
10
|
-
[[one, one], [:one, :one]]
|
11
|
-
end
|
12
|
-
|
13
|
-
it_behaves_like 'a passing predicate'
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'with value is not equal to the arg' do
|
17
|
-
let(:arguments_list) do
|
18
|
-
# Strings are not equal. Yet
|
19
|
-
[[one, two], ['one', 'one']]
|
20
|
-
end
|
21
|
-
|
22
|
-
it_behaves_like 'a failing predicate'
|
23
|
-
end
|
24
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#int?' do
|
7
|
-
let(:predicate_name) { :int? }
|
8
|
-
|
9
|
-
context 'when value is an integer' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[
|
12
|
-
[1],
|
13
|
-
[33],
|
14
|
-
[7]
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
it_behaves_like 'a passing predicate'
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with value is not an integer' do
|
22
|
-
let(:arguments_list) do
|
23
|
-
[
|
24
|
-
[''],
|
25
|
-
[[]],
|
26
|
-
[{}],
|
27
|
-
[nil],
|
28
|
-
[:symbol],
|
29
|
-
[String]
|
30
|
-
]
|
31
|
-
end
|
32
|
-
|
33
|
-
it_behaves_like 'a failing predicate'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/logic/predicates'
|
4
|
-
|
5
|
-
RSpec.describe Dry::Logic::Predicates do
|
6
|
-
describe '#key?' do
|
7
|
-
let(:predicate_name) { :key? }
|
8
|
-
|
9
|
-
context 'when key is present in value' do
|
10
|
-
let(:arguments_list) do
|
11
|
-
[
|
12
|
-
[:name, { name: 'John' }],
|
13
|
-
[:age, { age: 18 }]
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
it_behaves_like 'a passing predicate'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with key is not present in value' do
|
21
|
-
let(:arguments_list) do
|
22
|
-
[
|
23
|
-
[:name, { age: 18 }],
|
24
|
-
[:age, { name: 'Jill' }]
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
it_behaves_like 'a failing predicate'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|