dry-logic 0.6.0 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -5
  3. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
  4. data/.github/ISSUE_TEMPLATE/---bug-report.md +34 -0
  5. data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
  6. data/.github/workflows/ci.yml +70 -0
  7. data/.github/workflows/docsite.yml +34 -0
  8. data/.github/workflows/sync_configs.yml +34 -0
  9. data/.gitignore +2 -1
  10. data/.rspec +1 -0
  11. data/.rubocop.yml +89 -0
  12. data/CHANGELOG.md +51 -2
  13. data/CODE_OF_CONDUCT.md +13 -0
  14. data/CONTRIBUTING.md +3 -3
  15. data/Gemfile +3 -0
  16. data/LICENSE +1 -1
  17. data/README.md +7 -7
  18. data/Rakefile +2 -0
  19. data/benchmarks/rule_application.rb +2 -0
  20. data/benchmarks/setup.rb +2 -0
  21. data/bin/console +1 -0
  22. data/docsite/source/index.html.md +54 -0
  23. data/docsite/source/operations.html.md +62 -0
  24. data/docsite/source/predicates.html.md +102 -0
  25. data/dry-logic.gemspec +8 -0
  26. data/examples/basic.rb +2 -0
  27. data/lib/dry-logic.rb +2 -0
  28. data/lib/dry/logic.rb +2 -0
  29. data/lib/dry/logic/appliable.rb +2 -0
  30. data/lib/dry/logic/evaluator.rb +2 -0
  31. data/lib/dry/logic/operations.rb +2 -0
  32. data/lib/dry/logic/operations/abstract.rb +5 -3
  33. data/lib/dry/logic/operations/and.rb +3 -1
  34. data/lib/dry/logic/operations/attr.rb +2 -0
  35. data/lib/dry/logic/operations/binary.rb +2 -0
  36. data/lib/dry/logic/operations/check.rb +3 -1
  37. data/lib/dry/logic/operations/each.rb +2 -0
  38. data/lib/dry/logic/operations/implication.rb +2 -0
  39. data/lib/dry/logic/operations/key.rb +4 -2
  40. data/lib/dry/logic/operations/negation.rb +2 -0
  41. data/lib/dry/logic/operations/or.rb +2 -0
  42. data/lib/dry/logic/operations/set.rb +2 -0
  43. data/lib/dry/logic/operations/unary.rb +2 -0
  44. data/lib/dry/logic/operations/xor.rb +2 -0
  45. data/lib/dry/logic/operators.rb +2 -0
  46. data/lib/dry/logic/predicates.rb +39 -21
  47. data/lib/dry/logic/result.rb +2 -0
  48. data/lib/dry/logic/rule.rb +5 -3
  49. data/lib/dry/logic/rule/interface.rb +20 -0
  50. data/lib/dry/logic/rule/predicate.rb +2 -0
  51. data/lib/dry/logic/rule_compiler.rb +2 -0
  52. data/lib/dry/logic/version.rb +3 -1
  53. data/spec/integration/result_spec.rb +2 -0
  54. data/spec/integration/rule_spec.rb +2 -0
  55. data/spec/shared/predicates.rb +2 -0
  56. data/spec/shared/rule.rb +2 -0
  57. data/spec/spec_helper.rb +6 -10
  58. data/spec/support/mutant.rb +2 -0
  59. data/spec/unit/operations/and_spec.rb +2 -0
  60. data/spec/unit/operations/attr_spec.rb +2 -0
  61. data/spec/unit/operations/check_spec.rb +2 -0
  62. data/spec/unit/operations/each_spec.rb +2 -0
  63. data/spec/unit/operations/implication_spec.rb +2 -0
  64. data/spec/unit/operations/key_spec.rb +2 -0
  65. data/spec/unit/operations/negation_spec.rb +2 -0
  66. data/spec/unit/operations/or_spec.rb +2 -0
  67. data/spec/unit/operations/set_spec.rb +2 -0
  68. data/spec/unit/operations/xor_spec.rb +2 -0
  69. data/spec/unit/predicates/array_spec.rb +2 -0
  70. data/spec/unit/predicates/attr_spec.rb +2 -0
  71. data/spec/unit/predicates/bool_spec.rb +3 -1
  72. data/spec/unit/predicates/bytesize_spec.rb +48 -0
  73. data/spec/unit/predicates/case_spec.rb +2 -0
  74. data/spec/unit/predicates/date_spec.rb +2 -0
  75. data/spec/unit/predicates/date_time_spec.rb +3 -1
  76. data/spec/unit/predicates/decimal_spec.rb +3 -1
  77. data/spec/unit/predicates/empty_spec.rb +2 -0
  78. data/spec/unit/predicates/eql_spec.rb +2 -0
  79. data/spec/unit/predicates/even_spec.rb +2 -0
  80. data/spec/unit/predicates/excluded_from_spec.rb +2 -0
  81. data/spec/unit/predicates/excludes_spec.rb +2 -0
  82. data/spec/unit/predicates/false_spec.rb +3 -1
  83. data/spec/unit/predicates/filled_spec.rb +2 -0
  84. data/spec/unit/predicates/float_spec.rb +2 -0
  85. data/spec/unit/predicates/format_spec.rb +2 -0
  86. data/spec/unit/predicates/gt_spec.rb +2 -0
  87. data/spec/unit/predicates/gteq_spec.rb +2 -0
  88. data/spec/unit/predicates/hash_spec.rb +40 -0
  89. data/spec/unit/predicates/included_in_spec.rb +2 -0
  90. data/spec/unit/predicates/int_spec.rb +2 -0
  91. data/spec/unit/predicates/key_spec.rb +2 -0
  92. data/spec/unit/predicates/lt_spec.rb +2 -0
  93. data/spec/unit/predicates/lteq_spec.rb +2 -0
  94. data/spec/unit/predicates/max_bytesize_spec.rb +39 -0
  95. data/spec/unit/predicates/max_size_spec.rb +2 -0
  96. data/spec/unit/predicates/min_bytesize_spec.rb +39 -0
  97. data/spec/unit/predicates/min_size_spec.rb +2 -0
  98. data/spec/unit/predicates/none_spec.rb +2 -0
  99. data/spec/unit/predicates/not_eql_spec.rb +2 -0
  100. data/spec/unit/predicates/number_spec.rb +2 -0
  101. data/spec/unit/predicates/odd_spec.rb +2 -0
  102. data/spec/unit/predicates/respond_to_spec.rb +31 -0
  103. data/spec/unit/predicates/size_spec.rb +2 -0
  104. data/spec/unit/predicates/str_spec.rb +2 -0
  105. data/spec/unit/predicates/time_spec.rb +3 -1
  106. data/spec/unit/predicates/true_spec.rb +3 -1
  107. data/spec/unit/predicates/type_spec.rb +2 -0
  108. data/spec/unit/predicates/uuid_v4_spec.rb +29 -0
  109. data/spec/unit/predicates_spec.rb +2 -0
  110. data/spec/unit/rule/predicate_spec.rb +2 -0
  111. data/spec/unit/rule_compiler_spec.rb +2 -0
  112. data/spec/unit/rule_spec.rb +14 -3
  113. metadata +30 -6
  114. data/.travis.yml +0 -31
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -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 date' do
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 date' do
9
+ context 'when value is a decimal' do
8
10
  let(:arguments_list) do
9
11
  [[1.2.to_d]]
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates, '#eql?' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -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 a date' do
9
+ context 'when value is false' do
8
10
  let(:arguments_list) do
9
11
  [[false]]
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates, '#format?' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -0,0 +1,40 @@
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/logic/predicates'
4
+
5
+ RSpec.describe Dry::Logic::Predicates do
6
+ describe '#max_bytesize?' do
7
+ let(:predicate_name) { :max_bytesize? }
8
+
9
+ context 'when value size is less than n' do
10
+ let(:arguments_list) do
11
+ [
12
+ [5, 'こa']
13
+ ]
14
+ end
15
+
16
+ it_behaves_like 'a passing predicate'
17
+ end
18
+
19
+ context 'when value size is equal to n' do
20
+ let(:arguments_list) do
21
+ [
22
+ [5, 'こab']
23
+ ]
24
+ end
25
+
26
+ it_behaves_like 'a passing predicate'
27
+ end
28
+
29
+ context 'with value size is greater than n' do
30
+ let(:arguments_list) do
31
+ [
32
+ [5, 'こabc']
33
+ ]
34
+ end
35
+
36
+ it_behaves_like 'a failing predicate'
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/logic/predicates'
4
+
5
+ RSpec.describe Dry::Logic::Predicates do
6
+ describe '#min_bytesize?' do
7
+ let(:predicate_name) { :min_bytesize? }
8
+
9
+ context 'when value size is greater than n' do
10
+ let(:arguments_list) do
11
+ [
12
+ [3, 'こa']
13
+ ]
14
+ end
15
+
16
+ it_behaves_like 'a passing predicate'
17
+ end
18
+
19
+ context 'when value size is equal to n' do
20
+ let(:arguments_list) do
21
+ [
22
+ [5, 'こab']
23
+ ]
24
+ end
25
+
26
+ it_behaves_like 'a passing predicate'
27
+ end
28
+
29
+ context 'with value size is less than n' do
30
+ let(:arguments_list) do
31
+ [
32
+ [5, 'こ']
33
+ ]
34
+ end
35
+
36
+ it_behaves_like 'a failing predicate'
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates, '#not_eql?' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -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 date' do
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 a date' do
9
+ context 'when value is true' do
8
10
  let(:arguments_list) do
9
11
  [[true]]
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -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