dry-logic 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +113 -25
  3. data/LICENSE +1 -1
  4. data/README.md +12 -14
  5. data/dry-logic.gemspec +26 -20
  6. data/lib/dry-logic.rb +1 -1
  7. data/lib/dry/logic.rb +2 -2
  8. data/lib/dry/logic/evaluator.rb +1 -1
  9. data/lib/dry/logic/operations.rb +11 -11
  10. data/lib/dry/logic/operations/abstract.rb +3 -3
  11. data/lib/dry/logic/operations/and.rb +3 -3
  12. data/lib/dry/logic/operations/attr.rb +1 -1
  13. data/lib/dry/logic/operations/binary.rb +1 -1
  14. data/lib/dry/logic/operations/check.rb +3 -3
  15. data/lib/dry/logic/operations/each.rb +2 -2
  16. data/lib/dry/logic/operations/implication.rb +2 -2
  17. data/lib/dry/logic/operations/key.rb +3 -3
  18. data/lib/dry/logic/operations/negation.rb +2 -2
  19. data/lib/dry/logic/operations/or.rb +2 -2
  20. data/lib/dry/logic/operations/set.rb +3 -3
  21. data/lib/dry/logic/operations/unary.rb +1 -1
  22. data/lib/dry/logic/operations/xor.rb +2 -2
  23. data/lib/dry/logic/operators.rb +4 -4
  24. data/lib/dry/logic/predicates.rb +33 -8
  25. data/lib/dry/logic/result.rb +2 -2
  26. data/lib/dry/logic/rule.rb +8 -8
  27. data/lib/dry/logic/rule/interface.rb +32 -37
  28. data/lib/dry/logic/rule/predicate.rb +3 -3
  29. data/lib/dry/logic/rule_compiler.rb +3 -3
  30. data/lib/dry/logic/version.rb +1 -1
  31. metadata +17 -166
  32. data/.codeclimate.yml +0 -12
  33. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  34. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -34
  35. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  36. data/.github/workflows/ci.yml +0 -70
  37. data/.github/workflows/docsite.yml +0 -34
  38. data/.github/workflows/sync_configs.yml +0 -34
  39. data/.gitignore +0 -9
  40. data/.rspec +0 -4
  41. data/.rubocop.yml +0 -89
  42. data/CODE_OF_CONDUCT.md +0 -13
  43. data/CONTRIBUTING.md +0 -29
  44. data/Gemfile +0 -16
  45. data/Rakefile +0 -14
  46. data/benchmarks/rule_application.rb +0 -30
  47. data/benchmarks/setup.rb +0 -13
  48. data/bin/console +0 -11
  49. data/docsite/source/index.html.md +0 -54
  50. data/docsite/source/operations.html.md +0 -62
  51. data/docsite/source/predicates.html.md +0 -102
  52. data/examples/basic.rb +0 -16
  53. data/spec/integration/result_spec.rb +0 -61
  54. data/spec/integration/rule_spec.rb +0 -55
  55. data/spec/shared/predicates.rb +0 -59
  56. data/spec/shared/rule.rb +0 -74
  57. data/spec/spec_helper.rb +0 -30
  58. data/spec/support/mutant.rb +0 -11
  59. data/spec/unit/operations/and_spec.rb +0 -70
  60. data/spec/unit/operations/attr_spec.rb +0 -29
  61. data/spec/unit/operations/check_spec.rb +0 -51
  62. data/spec/unit/operations/each_spec.rb +0 -49
  63. data/spec/unit/operations/implication_spec.rb +0 -32
  64. data/spec/unit/operations/key_spec.rb +0 -135
  65. data/spec/unit/operations/negation_spec.rb +0 -51
  66. data/spec/unit/operations/or_spec.rb +0 -75
  67. data/spec/unit/operations/set_spec.rb +0 -43
  68. data/spec/unit/operations/xor_spec.rb +0 -63
  69. data/spec/unit/predicates/array_spec.rb +0 -43
  70. data/spec/unit/predicates/attr_spec.rb +0 -31
  71. data/spec/unit/predicates/bool_spec.rb +0 -36
  72. data/spec/unit/predicates/bytesize_spec.rb +0 -48
  73. data/spec/unit/predicates/case_spec.rb +0 -35
  74. data/spec/unit/predicates/date_spec.rb +0 -33
  75. data/spec/unit/predicates/date_time_spec.rb +0 -33
  76. data/spec/unit/predicates/decimal_spec.rb +0 -34
  77. data/spec/unit/predicates/empty_spec.rb +0 -40
  78. data/spec/unit/predicates/eql_spec.rb +0 -23
  79. data/spec/unit/predicates/even_spec.rb +0 -33
  80. data/spec/unit/predicates/excluded_from_spec.rb +0 -37
  81. data/spec/unit/predicates/excludes_spec.rb +0 -58
  82. data/spec/unit/predicates/false_spec.rb +0 -37
  83. data/spec/unit/predicates/filled_spec.rb +0 -40
  84. data/spec/unit/predicates/float_spec.rb +0 -33
  85. data/spec/unit/predicates/format_spec.rb +0 -23
  86. data/spec/unit/predicates/gt_spec.rb +0 -42
  87. data/spec/unit/predicates/gteq_spec.rb +0 -42
  88. data/spec/unit/predicates/hash_spec.rb +0 -40
  89. data/spec/unit/predicates/included_in_spec.rb +0 -37
  90. data/spec/unit/predicates/includes_spec.rb +0 -24
  91. data/spec/unit/predicates/int_spec.rb +0 -36
  92. data/spec/unit/predicates/key_spec.rb +0 -31
  93. data/spec/unit/predicates/lt_spec.rb +0 -42
  94. data/spec/unit/predicates/lteq_spec.rb +0 -42
  95. data/spec/unit/predicates/max_bytesize_spec.rb +0 -39
  96. data/spec/unit/predicates/max_size_spec.rb +0 -51
  97. data/spec/unit/predicates/min_bytesize_spec.rb +0 -39
  98. data/spec/unit/predicates/min_size_spec.rb +0 -51
  99. data/spec/unit/predicates/none_spec.rb +0 -30
  100. data/spec/unit/predicates/not_eql_spec.rb +0 -23
  101. data/spec/unit/predicates/number_spec.rb +0 -39
  102. data/spec/unit/predicates/odd_spec.rb +0 -33
  103. data/spec/unit/predicates/respond_to_spec.rb +0 -31
  104. data/spec/unit/predicates/size_spec.rb +0 -57
  105. data/spec/unit/predicates/str_spec.rb +0 -34
  106. data/spec/unit/predicates/time_spec.rb +0 -33
  107. data/spec/unit/predicates/true_spec.rb +0 -37
  108. data/spec/unit/predicates/type_spec.rb +0 -37
  109. data/spec/unit/predicates/uuid_v4_spec.rb +0 -29
  110. data/spec/unit/predicates_spec.rb +0 -25
  111. data/spec/unit/rule/predicate_spec.rb +0 -55
  112. data/spec/unit/rule_compiler_spec.rb +0 -129
  113. data/spec/unit/rule_spec.rb +0 -213
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry/logic/predicates'
4
-
5
- RSpec.describe Dry::Logic::Predicates do
6
- describe '#array?' do
7
- let(:predicate_name) { :array? }
8
-
9
- context 'when value is an array' do
10
- let(:arguments_list) do
11
- [
12
- [ [] ],
13
- [ ['other', 'array'] ],
14
- [ [123, 'really', :blah] ],
15
- [ Array.new ],
16
- [ [nil] ],
17
- [ [false] ],
18
- [ [true] ]
19
- ]
20
- end
21
-
22
- it_behaves_like 'a passing predicate'
23
- end
24
-
25
- context 'when value is not an array' do
26
- let(:arguments_list) do
27
- [
28
- [''],
29
- [{}],
30
- [nil],
31
- [:symbol],
32
- [String],
33
- [1],
34
- [1.0],
35
- [true],
36
- [Hash.new]
37
- ]
38
- end
39
-
40
- it_behaves_like 'a failing predicate'
41
- end
42
- end
43
- 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 '#attr?' do
7
- let(:predicate_name) { :attr? }
8
-
9
- context 'when value responds to the attr name' do
10
- let(:arguments_list) do
11
- [
12
- [:name, Struct.new(:name).new('John')],
13
- [:age, Struct.new(:age).new(18)]
14
- ]
15
- end
16
-
17
- it_behaves_like 'a passing predicate'
18
- end
19
-
20
- context 'with value does not respond to the attr name' do
21
- let(:arguments_list) do
22
- [
23
- [:name, Struct.new(:age).new(18)],
24
- [:age, Struct.new(:name).new('Jill')]
25
- ]
26
- end
27
-
28
- it_behaves_like 'a failing predicate'
29
- end
30
- end
31
- 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 '#bool?' do
7
- let(:predicate_name) { :bool? }
8
-
9
- context 'when value is a boolean' do
10
- let(:arguments_list) do
11
- [[true], [false]]
12
- end
13
-
14
- it_behaves_like 'a passing predicate'
15
- end
16
-
17
- context 'when value is not a bool' do
18
- let(:arguments_list) do
19
- [
20
- [''],
21
- [[]],
22
- [{}],
23
- [nil],
24
- [:symbol],
25
- [String],
26
- [1],
27
- [0],
28
- ['true'],
29
- ['false']
30
- ]
31
- end
32
-
33
- it_behaves_like 'a failing predicate'
34
- end
35
- end
36
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry/logic/predicates'
4
-
5
- RSpec.describe Dry::Logic::Predicates do
6
- describe '#bytesize?' do
7
- let(:predicate_name) { :bytesize? }
8
-
9
- context 'when value size is equal to n' do
10
- let(:arguments_list) do
11
- [
12
- [4, 'こa'],
13
- [1..8, 'こa']
14
- ]
15
- end
16
-
17
- it_behaves_like 'a passing predicate'
18
- end
19
-
20
- context 'when value size is greater than n' do
21
- let(:arguments_list) do
22
- [
23
- [3, 'こa'],
24
- [1..3, 'こa']
25
- ]
26
- end
27
-
28
- it_behaves_like 'a failing predicate'
29
- end
30
-
31
- context 'with value size is less than n' do
32
- let(:arguments_list) do
33
- [
34
- [5, 'こa'],
35
- [5..10, 'こa']
36
- ]
37
- end
38
-
39
- it_behaves_like 'a failing predicate'
40
- end
41
-
42
- context 'with an unsupported size' do
43
- it 'raises an error' do
44
- expect { Predicates[:bytesize?].call('oops', 1) }.to raise_error(ArgumentError, /oops/)
45
- end
46
- end
47
- end
48
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry/logic/predicates'
4
-
5
- RSpec.describe Dry::Logic::Predicates do
6
- describe '#case?' do
7
- let(:predicate_name) { :case? }
8
-
9
- context 'when the value matches the pattern' do
10
- let(:arguments_list) do
11
- [
12
- [11, 11],
13
- [:odd?.to_proc, 11],
14
- [/\Af/, 'foo'],
15
- [Integer, 11]
16
- ]
17
- end
18
-
19
- it_behaves_like 'a passing predicate'
20
- end
21
-
22
- context "when the value doesn't match the pattern" do
23
- let(:arguments_list) do
24
- [
25
- [13, 14],
26
- [:odd?.to_proc, 12],
27
- [/\Af/, 'bar'],
28
- [String, 11]
29
- ]
30
- end
31
-
32
- it_behaves_like 'a failing predicate'
33
- end
34
- end
35
- 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 '#date?' do
7
- let(:predicate_name) { :date? }
8
-
9
- context 'when value is a date' do
10
- let(:arguments_list) do
11
- [[Date.today]]
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,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry/logic/predicates'
4
-
5
- RSpec.describe Dry::Logic::Predicates do
6
- describe '#date_time?' do
7
- let(:predicate_name) { :date_time? }
8
-
9
- context 'when value is a datetime' do
10
- let(:arguments_list) do
11
- [[DateTime.now]]
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,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry/logic/predicates'
4
-
5
- RSpec.describe Dry::Logic::Predicates do
6
- describe '#decimal?' do
7
- let(:predicate_name) { :decimal? }
8
-
9
- context 'when value is a decimal' do
10
- let(:arguments_list) do
11
- [[1.2.to_d]]
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
- [1.0]
28
- ]
29
- end
30
-
31
- it_behaves_like 'a failing predicate'
32
- end
33
- end
34
- 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 '#empty?' do
7
- let(:predicate_name) { :empty? }
8
-
9
- context 'when value is empty' do
10
- let(:arguments_list) do
11
- [
12
- [''],
13
- [[]],
14
- [{}],
15
- [nil]
16
- ]
17
- end
18
-
19
- it_behaves_like 'a passing predicate'
20
- end
21
-
22
- context 'with value is not empty' do
23
- let(:arguments_list) do
24
- [
25
- ['Jill'],
26
- [[1, 2, 3]],
27
- [{ name: 'John' }],
28
- [true],
29
- [false],
30
- ['1'],
31
- ['0'],
32
- [:symbol],
33
- [String]
34
- ]
35
- end
36
-
37
- it_behaves_like 'a failing predicate'
38
- end
39
- end
40
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry/logic/predicates'
4
-
5
- RSpec.describe Dry::Logic::Predicates, '#eql?' do
6
- let(:predicate_name) { :eql? }
7
-
8
- context 'when value is equal to the arg' do
9
- let(:arguments_list) do
10
- [['Foo', 'Foo']]
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
- [['Bar', 'Foo']]
19
- end
20
-
21
- it_behaves_like 'a failing predicate'
22
- end
23
- 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 '#even?' do
7
- let(:predicate_name) { :even? }
8
-
9
- context 'when value is an odd int' do
10
- let(:arguments_list) do
11
- [
12
- [13],
13
- [1],
14
- [1111]
15
- ]
16
- end
17
-
18
- it_behaves_like 'a failing predicate'
19
- end
20
-
21
- context 'with value is an even int' do
22
- let(:arguments_list) do
23
- [
24
- [0],
25
- [2],
26
- [2222]
27
- ]
28
- end
29
-
30
- it_behaves_like 'a passing predicate'
31
- end
32
- end
33
- 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 '#excluded_from?' do
7
- let(:predicate_name) { :excluded_from? }
8
-
9
- context 'when value is not present in list' do
10
- let(:arguments_list) do
11
- [
12
- [['Jill', 'John'], 'Jack'],
13
- [1..2, 0],
14
- [1..2, 3],
15
- [[nil, false], true]
16
- ]
17
- end
18
-
19
- it_behaves_like 'a passing predicate'
20
- end
21
-
22
- context 'with value is present in list' do
23
- let(:arguments_list) do
24
- [
25
- [['Jill', 'John'], 'Jill'],
26
- [['Jill', 'John'], 'John'],
27
- [1..2, 1],
28
- [1..2, 2],
29
- [[nil, false], nil],
30
- [[nil, false], false]
31
- ]
32
- end
33
-
34
- it_behaves_like 'a failing predicate'
35
- end
36
- end
37
- end
@@ -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