dry-logic 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +76 -26
  3. data/LICENSE +1 -1
  4. data/README.md +12 -14
  5. data/dry-logic.gemspec +27 -20
  6. data/lib/dry/logic/predicates.rb +1 -1
  7. data/lib/dry/logic/rule/interface.rb +1 -1
  8. data/lib/dry/logic/version.rb +1 -1
  9. metadata +9 -150
  10. data/.codeclimate.yml +0 -12
  11. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  12. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -34
  13. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  14. data/.github/workflows/ci.yml +0 -70
  15. data/.github/workflows/docsite.yml +0 -34
  16. data/.github/workflows/sync_configs.yml +0 -34
  17. data/.gitignore +0 -9
  18. data/.rspec +0 -4
  19. data/.rubocop.yml +0 -89
  20. data/CODE_OF_CONDUCT.md +0 -13
  21. data/CONTRIBUTING.md +0 -29
  22. data/Gemfile +0 -16
  23. data/Rakefile +0 -14
  24. data/benchmarks/rule_application.rb +0 -30
  25. data/benchmarks/setup.rb +0 -13
  26. data/bin/console +0 -11
  27. data/docsite/source/index.html.md +0 -54
  28. data/docsite/source/operations.html.md +0 -62
  29. data/docsite/source/predicates.html.md +0 -102
  30. data/examples/basic.rb +0 -16
  31. data/spec/integration/result_spec.rb +0 -61
  32. data/spec/integration/rule_spec.rb +0 -55
  33. data/spec/shared/predicates.rb +0 -59
  34. data/spec/shared/rule.rb +0 -74
  35. data/spec/spec_helper.rb +0 -30
  36. data/spec/support/mutant.rb +0 -11
  37. data/spec/unit/operations/and_spec.rb +0 -70
  38. data/spec/unit/operations/attr_spec.rb +0 -29
  39. data/spec/unit/operations/check_spec.rb +0 -51
  40. data/spec/unit/operations/each_spec.rb +0 -49
  41. data/spec/unit/operations/implication_spec.rb +0 -32
  42. data/spec/unit/operations/key_spec.rb +0 -135
  43. data/spec/unit/operations/negation_spec.rb +0 -51
  44. data/spec/unit/operations/or_spec.rb +0 -75
  45. data/spec/unit/operations/set_spec.rb +0 -43
  46. data/spec/unit/operations/xor_spec.rb +0 -63
  47. data/spec/unit/predicates/array_spec.rb +0 -43
  48. data/spec/unit/predicates/attr_spec.rb +0 -31
  49. data/spec/unit/predicates/bool_spec.rb +0 -36
  50. data/spec/unit/predicates/bytesize_spec.rb +0 -48
  51. data/spec/unit/predicates/case_spec.rb +0 -35
  52. data/spec/unit/predicates/date_spec.rb +0 -33
  53. data/spec/unit/predicates/date_time_spec.rb +0 -33
  54. data/spec/unit/predicates/decimal_spec.rb +0 -34
  55. data/spec/unit/predicates/empty_spec.rb +0 -40
  56. data/spec/unit/predicates/eql_spec.rb +0 -23
  57. data/spec/unit/predicates/even_spec.rb +0 -33
  58. data/spec/unit/predicates/excluded_from_spec.rb +0 -37
  59. data/spec/unit/predicates/excludes_spec.rb +0 -58
  60. data/spec/unit/predicates/false_spec.rb +0 -37
  61. data/spec/unit/predicates/filled_spec.rb +0 -40
  62. data/spec/unit/predicates/float_spec.rb +0 -33
  63. data/spec/unit/predicates/format_spec.rb +0 -31
  64. data/spec/unit/predicates/gt_spec.rb +0 -42
  65. data/spec/unit/predicates/gteq_spec.rb +0 -42
  66. data/spec/unit/predicates/hash_spec.rb +0 -40
  67. data/spec/unit/predicates/included_in_spec.rb +0 -37
  68. data/spec/unit/predicates/includes_spec.rb +0 -24
  69. data/spec/unit/predicates/int_spec.rb +0 -36
  70. data/spec/unit/predicates/key_spec.rb +0 -31
  71. data/spec/unit/predicates/lt_spec.rb +0 -42
  72. data/spec/unit/predicates/lteq_spec.rb +0 -42
  73. data/spec/unit/predicates/max_bytesize_spec.rb +0 -39
  74. data/spec/unit/predicates/max_size_spec.rb +0 -51
  75. data/spec/unit/predicates/min_bytesize_spec.rb +0 -39
  76. data/spec/unit/predicates/min_size_spec.rb +0 -51
  77. data/spec/unit/predicates/none_spec.rb +0 -30
  78. data/spec/unit/predicates/not_eql_spec.rb +0 -23
  79. data/spec/unit/predicates/number_spec.rb +0 -39
  80. data/spec/unit/predicates/odd_spec.rb +0 -33
  81. data/spec/unit/predicates/respond_to_spec.rb +0 -31
  82. data/spec/unit/predicates/size_spec.rb +0 -57
  83. data/spec/unit/predicates/str_spec.rb +0 -34
  84. data/spec/unit/predicates/time_spec.rb +0 -33
  85. data/spec/unit/predicates/true_spec.rb +0 -37
  86. data/spec/unit/predicates/type_spec.rb +0 -37
  87. data/spec/unit/predicates/uuid_v4_spec.rb +0 -29
  88. data/spec/unit/predicates_spec.rb +0 -25
  89. data/spec/unit/rule/predicate_spec.rb +0 -55
  90. data/spec/unit/rule_compiler_spec.rb +0 -129
  91. data/spec/unit/rule_spec.rb +0 -213
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Operations::Or do
4
- subject(:operation) { Operations::Or.new(left, right) }
5
-
6
- include_context 'predicates'
7
-
8
- let(:left) { Rule::Predicate.build(nil?) }
9
- let(:right) { Rule::Predicate.build(gt?).curry(18) }
10
-
11
- let(:other) do
12
- Rule::Predicate.build(int?) & Rule::Predicate.build(lt?).curry(14)
13
- end
14
-
15
- describe '#call' do
16
- it 'calls left and right' do
17
- expect(operation.(nil)).to be_success
18
- expect(operation.(19)).to be_success
19
- expect(operation.(18)).to be_failure
20
- end
21
- end
22
-
23
- describe '#to_ast' do
24
- it 'returns ast' do
25
- expect(operation.to_ast).to eql(
26
- [:or, [
27
- [:predicate, [:nil?, [[:input, Undefined]]]],
28
- [:predicate, [:gt?, [[:num, 18], [:input, Undefined]]]]]
29
- ]
30
- )
31
- end
32
-
33
- it 'returns result ast' do
34
- expect(operation.(17).to_ast).to eql(
35
- [:or, [
36
- [:predicate, [:nil?, [[:input, 17]]]],
37
- [:predicate, [:gt?, [[:num, 18], [:input, 17]]]]]
38
- ]
39
- )
40
- end
41
-
42
- it 'returns failure result ast' do
43
- expect(operation.with(id: :age).(17).to_ast).to eql(
44
- [:failure, [:age, [:or, [
45
- [:predicate, [:nil?, [[:input, 17]]]],
46
- [:predicate, [:gt?, [[:num, 18], [:input, 17]]]]]
47
- ]]]
48
- )
49
- end
50
- end
51
-
52
- describe '#and' do
53
- it 'creates and with the other' do
54
- expect(operation.and(other).(nil)).to be_failure
55
- expect(operation.and(other).(19)).to be_failure
56
- expect(operation.and(other).(13)).to be_failure
57
- expect(operation.and(other).(14)).to be_failure
58
- end
59
- end
60
-
61
- describe '#or' do
62
- it 'creates or with the other' do
63
- expect(operation.or(other).(nil)).to be_success
64
- expect(operation.or(other).(19)).to be_success
65
- expect(operation.or(other).(13)).to be_success
66
- expect(operation.or(other).(14)).to be_failure
67
- end
68
- end
69
-
70
- describe '#to_s' do
71
- it 'returns string representation' do
72
- expect(operation.to_s).to eql('nil? OR gt?(18)')
73
- end
74
- end
75
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Operations::Set do
4
- subject(:operation) { Operations::Set.new(is_int, gt_18) }
5
-
6
- include_context 'predicates'
7
-
8
- let(:is_int) { Rule::Predicate.build(int?) }
9
- let(:gt_18) { Rule::Predicate.build(gt?, args: [18]) }
10
-
11
- describe '#call' do
12
- it 'applies all its rules to the input' do
13
- expect(operation.(19)).to be_success
14
- expect(operation.(17)).to be_failure
15
- end
16
- end
17
-
18
- describe '#to_ast' do
19
- it 'returns ast' do
20
- expect(operation.to_ast).to eql(
21
- [:set, [[:predicate, [:int?, [[:input, Undefined]]]], [:predicate, [:gt?, [[:num, 18], [:input, Undefined]]]]]]
22
- )
23
- end
24
-
25
- it 'returns result ast' do
26
- expect(operation.(17).to_ast).to eql(
27
- [:set, [[:predicate, [:gt?, [[:num, 18], [:input, 17]]]]]]
28
- )
29
- end
30
-
31
- it 'returns result ast with an :id' do
32
- expect(operation.with(id: :age).(17).to_ast).to eql(
33
- [:failure, [:age, [:set, [[:predicate, [:gt?, [[:num, 18], [:input, 17]]]]]]]]
34
- )
35
- end
36
- end
37
-
38
- describe '#to_s' do
39
- it 'returns string representation' do
40
- expect(operation.to_s).to eql('set(int?, gt?(18))')
41
- end
42
- end
43
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Operations::Xor do
4
- subject(:operation) { Operations::Xor.new(left, right) }
5
-
6
- include_context 'predicates'
7
-
8
- let(:left) { Rule::Predicate.build(array?) }
9
- let(:right) { Rule::Predicate.build(empty?) }
10
-
11
- let(:other) do
12
- Rule::Predicate.build(str?)
13
- end
14
-
15
- describe '#call' do
16
- it 'calls left and right' do
17
- expect(operation.(nil)).to be_success
18
- expect(operation.('')).to be_success
19
- expect(operation.([])).to be_failure
20
- end
21
- end
22
-
23
- describe '#to_ast' do
24
- it 'returns ast' do
25
- expect(operation.to_ast).to eql(
26
- [:xor, [[:predicate, [:array?, [[:input, Undefined]]]], [:predicate, [:empty?, [[:input, Undefined]]]]]]
27
- )
28
- end
29
-
30
- it 'returns result ast' do
31
- expect(operation.([]).to_ast).to eql(
32
- [:xor, [[:predicate, [:array?, [[:input, []]]]], [:predicate, [:empty?, [[:input, []]]]]]]
33
- )
34
- end
35
-
36
- it 'returns failure result ast' do
37
- expect(operation.with(id: :name).([]).to_ast).to eql(
38
- [:failure, [:name, [:xor, [[:predicate, [:array?, [[:input, []]]]], [:predicate, [:empty?, [[:input, []]]]]]]]]
39
- )
40
- end
41
- end
42
-
43
- describe '#and' do
44
- it 'creates conjunction with the other' do
45
- expect(operation.and(other).(nil)).to be_failure
46
- expect(operation.and(other).(19)).to be_failure
47
- expect(operation.and(other).('')).to be_success
48
- end
49
- end
50
-
51
- describe '#or' do
52
- it 'creates disjunction with the other' do
53
- expect(operation.or(other).([])).to be_failure
54
- expect(operation.or(other).('')).to be_success
55
- end
56
- end
57
-
58
- describe '#to_s' do
59
- it 'returns string representation' do
60
- expect(operation.to_s).to eql('array? XOR empty?')
61
- end
62
- end
63
- end
@@ -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