dry-logic 0.6.1 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -5
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +34 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.github/workflows/ci.yml +70 -0
- data/.github/workflows/docsite.yml +34 -0
- data/.github/workflows/sync_configs.yml +34 -0
- data/.gitignore +2 -1
- data/.rspec +1 -0
- data/.rubocop.yml +89 -0
- data/CHANGELOG.md +52 -3
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +3 -0
- data/LICENSE +1 -1
- data/README.md +6 -6
- data/Rakefile +2 -0
- data/benchmarks/rule_application.rb +2 -0
- data/benchmarks/setup.rb +2 -0
- data/bin/console +1 -0
- data/docsite/source/index.html.md +54 -0
- data/docsite/source/operations.html.md +62 -0
- data/docsite/source/predicates.html.md +102 -0
- data/dry-logic.gemspec +8 -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 +5 -3
- data/lib/dry/logic/operations/and.rb +3 -1
- 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 +3 -1
- 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 +4 -2
- 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 +39 -21
- data/lib/dry/logic/result.rb +2 -0
- data/lib/dry/logic/rule.rb +5 -3
- 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 +6 -10
- 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/bytesize_spec.rb +48 -0
- 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 +12 -2
- data/spec/unit/predicates/gt_spec.rb +2 -0
- data/spec/unit/predicates/gteq_spec.rb +2 -0
- data/spec/unit/predicates/hash_spec.rb +40 -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_bytesize_spec.rb +39 -0
- data/spec/unit/predicates/max_size_spec.rb +2 -0
- data/spec/unit/predicates/min_bytesize_spec.rb +39 -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 +6 -4
- metadata +30 -6
- data/.travis.yml +0 -31
@@ -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
|
@@ -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
|
@@ -5,7 +7,7 @@ RSpec.describe Dry::Logic::Predicates, '#format?' do
|
|
5
7
|
|
6
8
|
context 'when value matches provided regexp' do
|
7
9
|
let(:arguments_list) do
|
8
|
-
[['Foo'
|
10
|
+
[[/^F/, 'Foo']]
|
9
11
|
end
|
10
12
|
|
11
13
|
it_behaves_like 'a passing predicate'
|
@@ -13,7 +15,15 @@ RSpec.describe Dry::Logic::Predicates, '#format?' do
|
|
13
15
|
|
14
16
|
context 'when value does not match provided regexp' do
|
15
17
|
let(:arguments_list) do
|
16
|
-
[['Bar'
|
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]]
|
17
27
|
end
|
18
28
|
|
19
29
|
it_behaves_like 'a failing predicate'
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|