dry-logic 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +15 -1
- data/lib/dry/logic/predicates.rb +32 -2
- data/lib/dry/logic/version.rb +1 -1
- data/spec/unit/predicates/{exclusion_spec.rb → excluded_from_spec.rb} +2 -2
- data/spec/unit/predicates/excludes_spec.rb +56 -0
- data/spec/unit/predicates/{inclusion_spec.rb → included_in_spec.rb} +2 -2
- data/spec/unit/predicates/includes_spec.rb +56 -0
- data/spec/unit/predicates/not_eql_spec.rb +21 -0
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95bd134452791d94fdaf05fc2afc746040800e47
|
4
|
+
data.tar.gz: c1a47707cec851ac223ba9a7ce5dcbe46d0f2e9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8d2c782c82ee06c6f434c3aa768c85fc6ba4d35ec2196d2e4318d8870ff84368284a6774ebe1ee6db82681cd8c5551be971d86e59a56251f6547750ed43f520
|
7
|
+
data.tar.gz: 03d4dad7d29603a97541db67089f27b3d44a36114592273e5e6d6a102785186021bdc3070da72a11d675a0e5b2d10b1e0b85ac287db24d59d1745e5250783d0c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,22 @@
|
|
1
|
+
# v0.2.3 2016-05-11
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* `not_eql?`, `includes?`, `excludes?` predicates (fran-worley)
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
* Renamed `inclusion?` to `included_in?` and deprecated `inclusion?` (fran-worley)
|
10
|
+
* Renamed `exclusion?` to `excluded_from?` and deprecated `exclusion?` (fran-worley)
|
11
|
+
|
12
|
+
[Compare v0.2.2...v0.2.3](https://github.com/dryrb/dry-logic/compare/v0.2.2...v0.2.3)
|
13
|
+
|
14
|
+
|
1
15
|
# v0.2.2 2016-03-30
|
2
16
|
|
3
17
|
### Added
|
4
18
|
|
5
|
-
* `number?`
|
19
|
+
* `number?`, `odd?`, `even?` predicates (fran-worley)
|
6
20
|
|
7
21
|
[Compare v0.2.1...v0.2.2](https://github.com/dryrb/dry-logic/compare/v0.2.1...v0.2.2)
|
8
22
|
|
data/lib/dry/logic/predicates.rb
CHANGED
@@ -130,17 +130,47 @@ module Dry
|
|
130
130
|
end
|
131
131
|
|
132
132
|
predicate(:inclusion?) do |list, input|
|
133
|
-
|
133
|
+
::Kernel.warn 'inclusion is deprecated - use included_in instead.'
|
134
|
+
self[:included_in?].(list, input)
|
134
135
|
end
|
135
136
|
|
136
137
|
predicate(:exclusion?) do |list, input|
|
137
|
-
|
138
|
+
::Kernel.warn 'exclusion is deprecated - use excluded_from instead.'
|
139
|
+
self[:excluded_from?].(list, input)
|
140
|
+
end
|
141
|
+
|
142
|
+
predicate(:included_in?) do |list, input|
|
143
|
+
list.include?(input)
|
144
|
+
end
|
145
|
+
|
146
|
+
predicate(:excluded_from?) do |list, input|
|
147
|
+
!list.include?(input)
|
148
|
+
end
|
149
|
+
|
150
|
+
predicate(:includes?) do |value, input|
|
151
|
+
begin
|
152
|
+
if input.respond_to?(:include?)
|
153
|
+
input.include?(value)
|
154
|
+
else
|
155
|
+
false
|
156
|
+
end
|
157
|
+
rescue TypeError
|
158
|
+
false
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
predicate(:excludes?) do |value, input|
|
163
|
+
!self[:includes?].(value, input)
|
138
164
|
end
|
139
165
|
|
140
166
|
predicate(:eql?) do |left, right|
|
141
167
|
left.eql?(right)
|
142
168
|
end
|
143
169
|
|
170
|
+
predicate(:not_eql?) do |left, right|
|
171
|
+
!left.eql?(right)
|
172
|
+
end
|
173
|
+
|
144
174
|
predicate(:true?) do |value|
|
145
175
|
value === true
|
146
176
|
end
|
data/lib/dry/logic/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'dry/logic/predicates'
|
2
2
|
|
3
3
|
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#
|
5
|
-
let(:predicate_name) { :
|
4
|
+
describe '#excluded_from?' do
|
5
|
+
let(:predicate_name) { :excluded_from? }
|
6
6
|
|
7
7
|
context 'when value is not present in list' do
|
8
8
|
let(:arguments_list) do
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'dry/logic/predicates'
|
2
|
+
|
3
|
+
RSpec.describe Dry::Logic::Predicates do
|
4
|
+
describe '#excludes?' do
|
5
|
+
let(:predicate_name) { :excludes? }
|
6
|
+
|
7
|
+
context 'with input excludes value' do
|
8
|
+
let(:arguments_list) do
|
9
|
+
[
|
10
|
+
['Jack', ['Jill', 'John']],
|
11
|
+
[0, 1..2],
|
12
|
+
[3, 1..2],
|
13
|
+
['foo', 'Hello World'],
|
14
|
+
[:foo, { bar: 0 }],
|
15
|
+
[true, [nil, false]]
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
it_behaves_like 'a passing predicate'
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with input of invalid type' do
|
23
|
+
let(:arguments_list) do
|
24
|
+
[
|
25
|
+
[2, 1],
|
26
|
+
[1, nil],
|
27
|
+
["foo", 1],
|
28
|
+
[1, "foo"],
|
29
|
+
[1..2, "foo"],
|
30
|
+
["foo", 1..2],
|
31
|
+
[:key, "foo"]
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
it_behaves_like 'a passing predicate'
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when input includes value' do
|
39
|
+
let(:arguments_list) do
|
40
|
+
[
|
41
|
+
['Jill', ['Jill', 'John']],
|
42
|
+
['John', ['Jill', 'John']],
|
43
|
+
[1, 1..2],
|
44
|
+
[2, 1..2],
|
45
|
+
['Hello', 'Hello World'],
|
46
|
+
['World', 'Hello World'],
|
47
|
+
[:bar, { bar: 0 }],
|
48
|
+
[nil, [nil, false]],
|
49
|
+
[false, [nil, false]]
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
it_behaves_like 'a failing predicate'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'dry/logic/predicates'
|
2
2
|
|
3
3
|
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#
|
5
|
-
let(:predicate_name) { :
|
4
|
+
describe '#included_in?' do
|
5
|
+
let(:predicate_name) { :included_in? }
|
6
6
|
|
7
7
|
context 'when value is present in list' do
|
8
8
|
let(:arguments_list) do
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'dry/logic/predicates'
|
2
|
+
|
3
|
+
RSpec.describe Dry::Logic::Predicates do
|
4
|
+
describe '#includes?' do
|
5
|
+
let(:predicate_name) { :includes? }
|
6
|
+
|
7
|
+
context 'when input includes value' do
|
8
|
+
let(:arguments_list) do
|
9
|
+
[
|
10
|
+
['Jill', ['Jill', 'John']],
|
11
|
+
['John', ['Jill', 'John']],
|
12
|
+
[1, 1..2],
|
13
|
+
[2, 1..2],
|
14
|
+
['Hello', 'Hello World'],
|
15
|
+
['World', 'Hello World'],
|
16
|
+
[:bar, { bar: 0 }],
|
17
|
+
[nil, [nil, false]],
|
18
|
+
[false, [nil, false]]
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
it_behaves_like 'a passing predicate'
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with input of invalid type' do
|
26
|
+
let(:arguments_list) do
|
27
|
+
[
|
28
|
+
[2, 1],
|
29
|
+
[1, nil],
|
30
|
+
["foo", 1],
|
31
|
+
[1, "foo"],
|
32
|
+
[1..2, "foo"],
|
33
|
+
["foo", 1..2],
|
34
|
+
[:key, "foo"]
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
it_behaves_like 'a failing predicate'
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with input excludes value' do
|
42
|
+
let(:arguments_list) do
|
43
|
+
[
|
44
|
+
['Jack', ['Jill', 'John']],
|
45
|
+
[0, 1..2],
|
46
|
+
[3, 1..2],
|
47
|
+
['foo', 'Hello World'],
|
48
|
+
[:foo, { bar: 0 }],
|
49
|
+
[true, [nil, false]]
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
it_behaves_like 'a failing predicate'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'dry/logic/predicates'
|
2
|
+
|
3
|
+
RSpec.describe Dry::Logic::Predicates, '#not_eql?' do
|
4
|
+
let(:predicate_name) { :not_eql? }
|
5
|
+
|
6
|
+
context 'when value is equal to the arg' do
|
7
|
+
let(:arguments_list) do
|
8
|
+
[['Foo', 'Foo']]
|
9
|
+
end
|
10
|
+
|
11
|
+
it_behaves_like 'a failing predicate'
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with value is not equal to the arg' do
|
15
|
+
let(:arguments_list) do
|
16
|
+
[['Bar', 'Foo']]
|
17
|
+
end
|
18
|
+
|
19
|
+
it_behaves_like 'a passing predicate'
|
20
|
+
end
|
21
|
+
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|
@@ -139,14 +139,16 @@ files:
|
|
139
139
|
- spec/unit/predicates/empty_spec.rb
|
140
140
|
- spec/unit/predicates/eql_spec.rb
|
141
141
|
- spec/unit/predicates/even_spec.rb
|
142
|
-
- spec/unit/predicates/
|
142
|
+
- spec/unit/predicates/excluded_from_spec.rb
|
143
|
+
- spec/unit/predicates/excludes_spec.rb
|
143
144
|
- spec/unit/predicates/false_spec.rb
|
144
145
|
- spec/unit/predicates/filled_spec.rb
|
145
146
|
- spec/unit/predicates/float_spec.rb
|
146
147
|
- spec/unit/predicates/format_spec.rb
|
147
148
|
- spec/unit/predicates/gt_spec.rb
|
148
149
|
- spec/unit/predicates/gteq_spec.rb
|
149
|
-
- spec/unit/predicates/
|
150
|
+
- spec/unit/predicates/included_in_spec.rb
|
151
|
+
- spec/unit/predicates/includes_spec.rb
|
150
152
|
- spec/unit/predicates/int_spec.rb
|
151
153
|
- spec/unit/predicates/key_spec.rb
|
152
154
|
- spec/unit/predicates/lt_spec.rb
|
@@ -154,6 +156,7 @@ files:
|
|
154
156
|
- spec/unit/predicates/max_size_spec.rb
|
155
157
|
- spec/unit/predicates/min_size_spec.rb
|
156
158
|
- spec/unit/predicates/none_spec.rb
|
159
|
+
- spec/unit/predicates/not_eql_spec.rb
|
157
160
|
- spec/unit/predicates/number_spec.rb
|
158
161
|
- spec/unit/predicates/odd_spec.rb
|
159
162
|
- spec/unit/predicates/size_spec.rb
|
@@ -191,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
194
|
version: '0'
|
192
195
|
requirements: []
|
193
196
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.4.8
|
195
198
|
signing_key:
|
196
199
|
specification_version: 4
|
197
200
|
summary: Predicate logic with rule composition
|
@@ -207,14 +210,16 @@ test_files:
|
|
207
210
|
- spec/unit/predicates/empty_spec.rb
|
208
211
|
- spec/unit/predicates/eql_spec.rb
|
209
212
|
- spec/unit/predicates/even_spec.rb
|
210
|
-
- spec/unit/predicates/
|
213
|
+
- spec/unit/predicates/excluded_from_spec.rb
|
214
|
+
- spec/unit/predicates/excludes_spec.rb
|
211
215
|
- spec/unit/predicates/false_spec.rb
|
212
216
|
- spec/unit/predicates/filled_spec.rb
|
213
217
|
- spec/unit/predicates/float_spec.rb
|
214
218
|
- spec/unit/predicates/format_spec.rb
|
215
219
|
- spec/unit/predicates/gt_spec.rb
|
216
220
|
- spec/unit/predicates/gteq_spec.rb
|
217
|
-
- spec/unit/predicates/
|
221
|
+
- spec/unit/predicates/included_in_spec.rb
|
222
|
+
- spec/unit/predicates/includes_spec.rb
|
218
223
|
- spec/unit/predicates/int_spec.rb
|
219
224
|
- spec/unit/predicates/key_spec.rb
|
220
225
|
- spec/unit/predicates/lt_spec.rb
|
@@ -222,6 +227,7 @@ test_files:
|
|
222
227
|
- spec/unit/predicates/max_size_spec.rb
|
223
228
|
- spec/unit/predicates/min_size_spec.rb
|
224
229
|
- spec/unit/predicates/none_spec.rb
|
230
|
+
- spec/unit/predicates/not_eql_spec.rb
|
225
231
|
- spec/unit/predicates/number_spec.rb
|
226
232
|
- spec/unit/predicates/odd_spec.rb
|
227
233
|
- spec/unit/predicates/size_spec.rb
|
@@ -239,4 +245,3 @@ test_files:
|
|
239
245
|
- spec/unit/rule/set_spec.rb
|
240
246
|
- spec/unit/rule/value_spec.rb
|
241
247
|
- spec/unit/rule_compiler_spec.rb
|
242
|
-
has_rdoc:
|