dry-logic 0.4.2 → 0.5.0
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 +5 -5
- data/.gitignore +0 -1
- data/.travis.yml +18 -19
- data/CHANGELOG.md +52 -40
- data/Gemfile +0 -1
- data/README.md +0 -2
- data/bin/console +10 -0
- data/dry-logic.gemspec +0 -1
- data/lib/dry/logic/operations/key.rb +4 -4
- data/lib/dry/logic/operations/negation.rb +5 -1
- data/lib/dry/logic/predicates.rb +2 -1
- data/lib/dry/logic/rule_compiler.rb +2 -0
- data/lib/dry/logic/version.rb +1 -1
- data/spec/shared/predicates.rb +1 -1
- data/spec/unit/operations/key_spec.rb +14 -0
- data/spec/unit/operations/negation_spec.rb +9 -0
- data/spec/unit/operations/or_spec.rb +5 -5
- data/spec/unit/predicates/none_spec.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a6ff887f61b513496991a96d7903685886ab29dae71cb4f75185cd7866fd4b2
|
4
|
+
data.tar.gz: 9e063f346341b395ac21645f84319e619af19151e62bd97413badf246440d353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f643a0238e3b67c91c83af1e90cb4398279b4c01957ce663a5186ae8437a87e94c9d9cb2f7a2aabca1c7edb47be28a531317a044e58e270ffff59c44e6a9ccf5
|
7
|
+
data.tar.gz: 17b0ff20fc5c41258a537ad0c57e959cd3359765801261157772a62ee5d1ce525c15bca2ce92c8ee624b1fda67a5cf6cbf4228af552cf99efc8e8428026dbccb
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,31 +1,30 @@
|
|
1
1
|
language: ruby
|
2
|
-
dist: trusty
|
3
|
-
sudo: false
|
4
2
|
cache: bundler
|
5
|
-
|
3
|
+
sudo: false
|
4
|
+
bundler_args: --without benchmarks tools
|
5
|
+
before_install: gem update --system
|
6
|
+
before_script:
|
7
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
8
|
+
- chmod +x ./cc-test-reporter
|
9
|
+
- ./cc-test-reporter before-build
|
10
|
+
after_script:
|
11
|
+
- "[ -d coverage ] && ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
6
12
|
script:
|
7
|
-
- bundle exec rake
|
8
|
-
after_success:
|
9
|
-
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
13
|
+
- bundle exec rake
|
10
14
|
rvm:
|
11
|
-
- 2.
|
12
|
-
- 2.
|
13
|
-
- 2.
|
14
|
-
- 2.
|
15
|
-
- jruby-9.
|
16
|
-
- ruby-head
|
15
|
+
- 2.6.0
|
16
|
+
- 2.5.3
|
17
|
+
- 2.4.5
|
18
|
+
- 2.3.8
|
19
|
+
- jruby-9.2.5.0
|
17
20
|
env:
|
18
21
|
global:
|
19
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
20
22
|
- COVERAGE=true
|
21
|
-
matrix:
|
22
|
-
allow_failures:
|
23
|
-
- rvm: ruby-head
|
24
23
|
notifications:
|
25
24
|
email: false
|
26
25
|
webhooks:
|
27
26
|
urls:
|
28
27
|
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
29
|
-
on_success: change
|
30
|
-
on_failure: always
|
31
|
-
on_start: false
|
28
|
+
on_success: change # options: [always|never|change] default: always
|
29
|
+
on_failure: always # options: [always|never|change] default: always
|
30
|
+
on_start: false # default: false
|
data/CHANGELOG.md
CHANGED
@@ -1,25 +1,37 @@
|
|
1
|
+
# v0.5.0 2019-01-29
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
- `:nil?` predicate (`none?` is now an alias) (solnic)
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
- `Operation::Key#ast` will now return a correct AST with non-Undefined inputs (solnic)
|
10
|
+
|
11
|
+
[Compare v0.4.2...v0.5.0](https://github.com/dry-rb/dry-logic/compare/v0.4.2...v0.5.0)
|
12
|
+
|
1
13
|
# v0.4.2 2017-09-15
|
2
14
|
|
3
15
|
### Added
|
4
16
|
|
5
|
-
|
6
|
-
|
17
|
+
- New `:case?` predicate matches a value against the given object with `#===` (flash-gordon)
|
18
|
+
- New `:is?` predicate checks objects identity (using `#equal?`) (flash-gordon)
|
7
19
|
|
8
20
|
### Fixed
|
9
21
|
|
10
|
-
|
22
|
+
- A bug with using custom predicates within a standalone module in `dry-validation` (flash-gordon)
|
11
23
|
|
12
|
-
[Compare v0.4.1...v0.4.2(https://github.com/dry-rb/dry-logic/compare/v0.4.1...v0.4.2)
|
24
|
+
[Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-logic/compare/v0.4.1...v0.4.2)
|
13
25
|
|
14
26
|
# v0.4.1 2017-01-23
|
15
27
|
|
16
28
|
### Changed
|
17
29
|
|
18
|
-
|
30
|
+
- Predicates simply reuse other predicate methods instead of referring to them via `#[]` (georgemillo)
|
19
31
|
|
20
32
|
### Fixed
|
21
33
|
|
22
|
-
|
34
|
+
- Warnings on MRI 2.4.0 are gone (jtippett)
|
23
35
|
|
24
36
|
[Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-logic/compare/v0.4.0...v0.4.1)
|
25
37
|
|
@@ -29,25 +41,25 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
29
41
|
|
30
42
|
### Added
|
31
43
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
44
|
+
- `Rule#[]` which applies a rule and always returns `true` or `false` (solnic)
|
45
|
+
- `Rule#bind` which returns a rule with its predicate bound to a given object (solnic)
|
46
|
+
- `Rule#eval_args` which evaluates unbound-methods-args in the context of a given object (solnic)
|
47
|
+
- `Logic.Rule` builder function (solnic)
|
48
|
+
- Nice `#inspect` on rules and operation objects (solnic)
|
37
49
|
|
38
50
|
### Changed
|
39
51
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
- [BRAEKING] New result API (solnic)
|
53
|
+
- [BREAKING] `Predicate` is now `Rule::Predicate` (solnic)
|
54
|
+
- [BREAKING] `Rule::Conjunction` is now `Operation::And` (solnic)
|
55
|
+
- [BREAKING] `Rule::Disjunction` is now `Operation::Or` (solnic)
|
56
|
+
- [BREAKING] `Rule::ExlusiveDisjunction` is now `Operation::Xor` (solnic)
|
57
|
+
- [BREAKING] `Rule::Implication` is now `Operation::Implication` (solnic)
|
58
|
+
- [BREAKING] `Rule::Set` is now `Operation::Set` (solnic)
|
59
|
+
- [BREAKING] `Rule::Each` is now `Operation::Each` (solnic)
|
60
|
+
- [BREAKING] `Rule.new` accepts a predicate function as its first arg now (solnic)
|
61
|
+
- [BREAKING] `Rule#name` is now `Rule#id` (solnic)
|
62
|
+
- `Rule#parameters` is public now (solnic)
|
51
63
|
|
52
64
|
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-logic/compare/v0.3.0...v0.4.0)
|
53
65
|
|
@@ -55,14 +67,14 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
55
67
|
|
56
68
|
### Added
|
57
69
|
|
58
|
-
|
59
|
-
|
70
|
+
- `:type?` predicate imported from dry-types (solnic)
|
71
|
+
- `Rule#curry` interface (solnic)
|
60
72
|
|
61
73
|
### Changed
|
62
74
|
|
63
|
-
|
64
|
-
|
65
|
-
|
75
|
+
- Predicates AST now includes information about args (names & possible values) (fran-worley + solnic)
|
76
|
+
- Predicates raise errors when they are called with invalid arity (fran-worley + solnic)
|
77
|
+
- Rules no longer evaluate input twice when building result objects (solnic)
|
66
78
|
|
67
79
|
[Compare v0.2.3...v0.3.0](https://github.com/dry-rb/dry-logic/compare/v0.2.3...v0.3.0)
|
68
80
|
|
@@ -70,12 +82,12 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
70
82
|
|
71
83
|
### Added
|
72
84
|
|
73
|
-
|
85
|
+
- `not_eql?`, `includes?`, `excludes?` predicates (fran-worley)
|
74
86
|
|
75
87
|
### Changed
|
76
88
|
|
77
|
-
|
78
|
-
|
89
|
+
- Renamed `inclusion?` to `included_in?` and deprecated `inclusion?` (fran-worley)
|
90
|
+
- Renamed `exclusion?` to `excluded_from?` and deprecated `exclusion?` (fran-worley)
|
79
91
|
|
80
92
|
[Compare v0.2.2...v0.2.3](https://github.com/dry-rb/dry-logic/compare/v0.2.2...v0.2.3)
|
81
93
|
|
@@ -83,7 +95,7 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
83
95
|
|
84
96
|
### Added
|
85
97
|
|
86
|
-
|
98
|
+
- `number?`, `odd?`, `even?` predicates (fran-worley)
|
87
99
|
|
88
100
|
[Compare v0.2.1...v0.2.2](https://github.com/dry-rb/dry-logic/compare/v0.2.1...v0.2.2)
|
89
101
|
|
@@ -91,13 +103,13 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
91
103
|
|
92
104
|
### Fixed
|
93
105
|
|
94
|
-
|
106
|
+
- Result AST for `Rule::Each` correctly maps elements with eql inputs (solnic)
|
95
107
|
|
96
108
|
# v0.2.0 2016-03-11
|
97
109
|
|
98
110
|
### Changed
|
99
111
|
|
100
|
-
|
112
|
+
- Entire AST has been redefined (solnic)
|
101
113
|
|
102
114
|
[Compare v0.1.4...v0.2.0](https://github.com/dry-rb/dry-logic/compare/v0.1.4...v0.2.0)
|
103
115
|
|
@@ -105,7 +117,7 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
105
117
|
|
106
118
|
### Added
|
107
119
|
|
108
|
-
|
120
|
+
- Support for hash-names in `Check` and `Result` which can properly resolve input
|
109
121
|
from nested results (solnic)
|
110
122
|
|
111
123
|
[Compare v0.1.3...v0.1.4](https://github.com/dry-rb/dry-logic/compare/v0.1.3...v0.1.4)
|
@@ -114,11 +126,11 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
114
126
|
|
115
127
|
### Added
|
116
128
|
|
117
|
-
|
129
|
+
- Support for resolving input from `Rule::Result` (solnic)
|
118
130
|
|
119
131
|
### Changed
|
120
132
|
|
121
|
-
|
133
|
+
- `Check` and `Result` carry original input(s) (solnic)
|
122
134
|
|
123
135
|
[Compare v0.1.2...v0.1.3](https://github.com/dry-rb/dry-logic/compare/v0.1.2...v0.1.3)
|
124
136
|
|
@@ -126,7 +138,7 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
126
138
|
|
127
139
|
### Fixed
|
128
140
|
|
129
|
-
|
141
|
+
- `xor` returns wrapped results when used against another result-rule (solnic)
|
130
142
|
|
131
143
|
[Compare v0.1.1...v0.1.2](https://github.com/dry-rb/dry-logic/compare/v0.1.1...v0.1.2)
|
132
144
|
|
@@ -134,9 +146,9 @@ This is a partial rewrite focused on internal clean up and major performance imp
|
|
134
146
|
|
135
147
|
### Added
|
136
148
|
|
137
|
-
|
138
|
-
|
139
|
-
|
149
|
+
- `Rule::Attr` which can be applied to a data object with attr readers (SunnyMagadan)
|
150
|
+
- `Rule::Result` which can be applied to a result object (solnic)
|
151
|
+
- `true?` and `false?` predicates (solnic)
|
140
152
|
|
141
153
|
[Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-logic/compare/v0.1.0...v0.1.1)
|
142
154
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
[gem]: https://rubygems.org/gems/dry-logic
|
2
2
|
[travis]: https://travis-ci.org/dry-rb/dry-logic
|
3
|
-
[gemnasium]: https://gemnasium.com/dry-rb/dry-logic
|
4
3
|
[codeclimate]: https://codeclimate.com/github/dry-rb/dry-logic
|
5
4
|
[coveralls]: https://coveralls.io/r/dry-rb/dry-logic
|
6
5
|
[inchpages]: http://inch-ci.org/github/dry-rb/dry-logic
|
@@ -9,7 +8,6 @@
|
|
9
8
|
|
10
9
|
[][gem]
|
11
10
|
[][travis]
|
12
|
-
[][gemnasium]
|
13
11
|
[][codeclimate]
|
14
12
|
[][codeclimate]
|
15
13
|
[][inchpages]
|
data/bin/console
ADDED
data/dry-logic.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.license = 'MIT'
|
11
11
|
|
12
12
|
spec.files = `git ls-files -z`.split("\x0")
|
13
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
13
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
14
|
spec.require_paths = ['lib']
|
16
15
|
|
@@ -49,11 +49,11 @@ module Dry
|
|
49
49
|
rule[evaluator[hash]]
|
50
50
|
end
|
51
51
|
|
52
|
-
def ast(input =
|
53
|
-
if input
|
54
|
-
[type, [path, rule.ast(evaluator[input])]]
|
55
|
-
else
|
52
|
+
def ast(input = Undefined)
|
53
|
+
if input.equal?(Undefined) || !input.is_a?(Hash)
|
56
54
|
[type, [path, rule.ast]]
|
55
|
+
else
|
56
|
+
[type, [path, rule.ast(evaluator[input])]]
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
data/lib/dry/logic/predicates.rb
CHANGED
data/lib/dry/logic/version.rb
CHANGED
data/spec/shared/predicates.rb
CHANGED
@@ -92,6 +92,20 @@ RSpec.describe Operations::Key do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
describe '#ast' do
|
96
|
+
it 'returns ast without the input' do
|
97
|
+
expect(operation.ast).to eql(
|
98
|
+
[:key, [:user, [:predicate, [:key?, [[:name, :age], [:input, Undefined]]]]]]
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns ast with the input' do
|
103
|
+
expect(operation.ast(user: 'jane')).to eql(
|
104
|
+
[:key, [:user, [:predicate, [:key?, [[:name, :age], [:input, 'jane']]]]]]
|
105
|
+
)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
95
109
|
describe '#and' do
|
96
110
|
subject(:operation) do
|
97
111
|
Operations::Key.new(Rule::Predicate.new(str?), name: [:user, :name])
|
@@ -10,6 +10,15 @@ RSpec.describe Operations::Negation do
|
|
10
10
|
expect(operation.('19')).to be_success
|
11
11
|
expect(operation.(17)).to be_failure
|
12
12
|
end
|
13
|
+
|
14
|
+
context 'double negation' do
|
15
|
+
subject(:double_negation) { Operations::Negation.new(operation) }
|
16
|
+
|
17
|
+
it 'works as rule' do
|
18
|
+
expect(double_negation.('19')).to be_failure
|
19
|
+
expect(double_negation.(17)).to be_success
|
20
|
+
end
|
21
|
+
end
|
13
22
|
end
|
14
23
|
|
15
24
|
describe '#to_ast' do
|
@@ -3,7 +3,7 @@ RSpec.describe Operations::Or do
|
|
3
3
|
|
4
4
|
include_context 'predicates'
|
5
5
|
|
6
|
-
let(:left) { Rule::Predicate.new(
|
6
|
+
let(:left) { Rule::Predicate.new(nil?) }
|
7
7
|
let(:right) { Rule::Predicate.new(gt?).curry(18) }
|
8
8
|
|
9
9
|
let(:other) do
|
@@ -22,7 +22,7 @@ RSpec.describe Operations::Or do
|
|
22
22
|
it 'returns ast' do
|
23
23
|
expect(operation.to_ast).to eql(
|
24
24
|
[:or, [
|
25
|
-
[:predicate, [:
|
25
|
+
[:predicate, [:nil?, [[:input, Undefined]]]],
|
26
26
|
[:predicate, [:gt?, [[:num, 18], [:input, Undefined]]]]]
|
27
27
|
]
|
28
28
|
)
|
@@ -31,7 +31,7 @@ RSpec.describe Operations::Or do
|
|
31
31
|
it 'returns result ast' do
|
32
32
|
expect(operation.(17).to_ast).to eql(
|
33
33
|
[:or, [
|
34
|
-
[:predicate, [:
|
34
|
+
[:predicate, [:nil?, [[:input, 17]]]],
|
35
35
|
[:predicate, [:gt?, [[:num, 18], [:input, 17]]]]]
|
36
36
|
]
|
37
37
|
)
|
@@ -40,7 +40,7 @@ RSpec.describe Operations::Or do
|
|
40
40
|
it 'returns failure result ast' do
|
41
41
|
expect(operation.with(id: :age).(17).to_ast).to eql(
|
42
42
|
[:failure, [:age, [:or, [
|
43
|
-
[:predicate, [:
|
43
|
+
[:predicate, [:nil?, [[:input, 17]]]],
|
44
44
|
[:predicate, [:gt?, [[:num, 18], [:input, 17]]]]]
|
45
45
|
]]]
|
46
46
|
)
|
@@ -67,7 +67,7 @@ RSpec.describe Operations::Or do
|
|
67
67
|
|
68
68
|
describe '#to_s' do
|
69
69
|
it 'returns string representation' do
|
70
|
-
expect(operation.to_s).to eql('
|
70
|
+
expect(operation.to_s).to eql('nil? OR gt?(18)')
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-core
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- LICENSE
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
|
+
- bin/console
|
122
123
|
- dry-logic.gemspec
|
123
124
|
- examples/basic.rb
|
124
125
|
- lib/dry-logic.rb
|
@@ -220,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
221
|
- !ruby/object:Gem::Version
|
221
222
|
version: '0'
|
222
223
|
requirements: []
|
223
|
-
|
224
|
-
rubygems_version: 2.6.11
|
224
|
+
rubygems_version: 3.0.2
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: Predicate logic with rule composition
|