predicate 2.7.1 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/predicate/asserter.rb +12 -0
- data/lib/predicate/nodes/eq.rb +6 -0
- data/lib/predicate/nodes/expr.rb +4 -0
- data/lib/predicate/nodes/neq.rb +6 -0
- data/lib/predicate/version.rb +2 -2
- data/lib/predicate.rb +5 -0
- data/spec/predicate/test_assert!.rb +67 -0
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b905f4aeb37f046ccef6ac9b7afc674f19f3a91f865be488354daecc8ef28f1
|
4
|
+
data.tar.gz: d205d1b1e789b2f549ccfe6181f7dfc66a7a650346050c1497521000e243f85f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9ec299aaa242f521d53042df037536e618e00cceebe612c56d083eb3ea62ae7175c9dcfefe45b9dcf52df3b22c4a594a6c1456047a807a924ae4fb0029a60c4
|
7
|
+
data.tar.gz: c3f88782791b4fbb0d645be5d24a7bfb54b4bddc7128b30b84e60c2fc66f9bb9fa4407620dcbed6f12cb8773fb112cf223ab38cbc96a43fd8c15c96ba66f0e9d
|
data/lib/predicate/nodes/eq.rb
CHANGED
@@ -46,6 +46,12 @@ class Predicate
|
|
46
46
|
left.evaluate(tuple) == right.evaluate(tuple)
|
47
47
|
end
|
48
48
|
|
49
|
+
def assert!(tuple, asserter = Asserter.new)
|
50
|
+
l, r = left.evaluate(tuple), right.evaluate(tuple)
|
51
|
+
asserter.assert_equal(l, r)
|
52
|
+
l
|
53
|
+
end
|
54
|
+
|
49
55
|
def to_hash
|
50
56
|
if left.identifier? && right.literal? && !right.has_placeholder?
|
51
57
|
{ left.name => right.value }
|
data/lib/predicate/nodes/expr.rb
CHANGED
@@ -50,6 +50,10 @@ class Predicate
|
|
50
50
|
sexpr([:or, self, other])
|
51
51
|
end
|
52
52
|
|
53
|
+
def assert!(tuple, asserter = Asserter.new)
|
54
|
+
asserter.assert(evaluate(tuple))
|
55
|
+
end
|
56
|
+
|
53
57
|
def and_split(attr_list)
|
54
58
|
# If we have no reference to attr_list, then we are P2, else we are P1
|
55
59
|
(free_variables & attr_list).empty? ? [ tautology, self ] : [ self, tautology ]
|
data/lib/predicate/nodes/neq.rb
CHANGED
data/lib/predicate/version.rb
CHANGED
data/lib/predicate.rb
CHANGED
@@ -6,6 +6,7 @@ require_relative 'predicate/sugar'
|
|
6
6
|
require_relative 'predicate/grammar'
|
7
7
|
require_relative 'predicate/processors'
|
8
8
|
require_relative 'predicate/dsl'
|
9
|
+
require_relative 'predicate/asserter'
|
9
10
|
class Predicate
|
10
11
|
|
11
12
|
class Error < StandardError; end
|
@@ -125,6 +126,10 @@ class Predicate
|
|
125
126
|
expr.evaluate(tuple)
|
126
127
|
end
|
127
128
|
|
129
|
+
def assert!(tuple = {})
|
130
|
+
expr.assert!(tuple)
|
131
|
+
end
|
132
|
+
|
128
133
|
# Splits this predicate, say P, as too predicates P1 & P2
|
129
134
|
# such that `P <=> P1 & P2` and P2 makes no reference to
|
130
135
|
# any attribute in `attr_list`.
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class Predicate
|
3
|
+
describe Predicate, "assert!" do
|
4
|
+
|
5
|
+
describe "eq" do
|
6
|
+
let(:predicate) {
|
7
|
+
Predicate.eq(:x, 2)
|
8
|
+
}
|
9
|
+
|
10
|
+
subject{
|
11
|
+
predicate.assert!(input)
|
12
|
+
}
|
13
|
+
|
14
|
+
context "when ok" do
|
15
|
+
let(:input){
|
16
|
+
{ x: 2 }
|
17
|
+
}
|
18
|
+
it 'works and returns 2' do
|
19
|
+
expect(subject).to eql(2)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when ko" do
|
24
|
+
let(:input){
|
25
|
+
{ x: 3 }
|
26
|
+
}
|
27
|
+
it 'works and throws' do
|
28
|
+
expect{
|
29
|
+
subject
|
30
|
+
}.to raise_error(Minitest::Assertion, /Expected: 3\s+Actual: 2/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "neq" do
|
36
|
+
let(:predicate) {
|
37
|
+
Predicate.neq(:x, 2)
|
38
|
+
}
|
39
|
+
|
40
|
+
subject{
|
41
|
+
predicate.assert!(input)
|
42
|
+
}
|
43
|
+
|
44
|
+
context "when ok" do
|
45
|
+
let(:input){
|
46
|
+
{ x: 3 }
|
47
|
+
}
|
48
|
+
it 'works and returns 3' do
|
49
|
+
expect(subject).to eql(3)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when ko" do
|
54
|
+
let(:input){
|
55
|
+
{ x: 2 }
|
56
|
+
}
|
57
|
+
it 'works and throws' do
|
58
|
+
expect{
|
59
|
+
subject
|
60
|
+
}.to raise_error(Minitest::Assertion, /Expected 2 to not be equal to 2./)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: predicate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sexpr
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +121,7 @@ files:
|
|
107
121
|
- Rakefile
|
108
122
|
- bin/g
|
109
123
|
- lib/predicate.rb
|
124
|
+
- lib/predicate/asserter.rb
|
110
125
|
- lib/predicate/dsl.rb
|
111
126
|
- lib/predicate/factory.rb
|
112
127
|
- lib/predicate/grammar.rb
|
@@ -219,6 +234,7 @@ files:
|
|
219
234
|
- spec/postgres/test_to_postgres.rb
|
220
235
|
- spec/postgres/test_to_sequel.rb
|
221
236
|
- spec/predicate/test_and_split.rb
|
237
|
+
- spec/predicate/test_assert!.rb
|
222
238
|
- spec/predicate/test_attr_split.rb
|
223
239
|
- spec/predicate/test_bind.rb
|
224
240
|
- spec/predicate/test_bool_and.rb
|
@@ -264,8 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
280
|
- !ruby/object:Gem::Version
|
265
281
|
version: '0'
|
266
282
|
requirements: []
|
267
|
-
|
268
|
-
rubygems_version: 2.6.14.4
|
283
|
+
rubygems_version: 3.1.6
|
269
284
|
signing_key:
|
270
285
|
specification_version: 4
|
271
286
|
summary: Predicate provides a simple class and processors to encode and manipulate
|