predicate 2.9.0 → 2.10.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 +4 -4
- data/lib/predicate/sequel/to_sequel.rb +6 -1
- data/lib/predicate/version.rb +1 -1
- data/spec/predicate/test_to_hashes.rb +72 -0
- data/spec/sequel/test_to_sequel.rb +38 -15
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba74ff534d4a9b58d4fdc9dc671d17275d9d01d65b391b509be68fd6500fb75b
|
|
4
|
+
data.tar.gz: 964c06320295c968a80547e7af048bfd6382638414e724734f7b79ab9c739ac1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4ac5d9e093b57a77ca942c11f602e13460d9e9154d6f5b271651c3ea7972c6fc0fb01a19b66c1a462e2c2d0d8760b7479ec75db566ef83fa7c63c1b3ab62db9
|
|
7
|
+
data.tar.gz: 275ebdd55119eca9b6ef5513f90ba0a2e9664cf2a70fa3fa28da342fcbb0ce91ade41154cbc04e187c89c33b34473d0a83fe98828aec40c1573dc465f1031518
|
|
@@ -110,11 +110,16 @@ class Predicate
|
|
|
110
110
|
raise Error, "Unable to compile #{sexpr} to Sequel"
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
+
def on_native(sexpr)
|
|
114
|
+
return sexpr.last.sql_literal if sexpr.last.respond_to?(:sql_literal)
|
|
115
|
+
return sexpr.last.sql if sexpr.last.respond_to?(:sql)
|
|
116
|
+
on_unsupported(sexpr)
|
|
117
|
+
end
|
|
118
|
+
|
|
113
119
|
def on_unsupported(sexpr)
|
|
114
120
|
raise NotSupportedError, "Unsupported predicate #{sexpr}"
|
|
115
121
|
end
|
|
116
122
|
alias :on_var :on_unsupported
|
|
117
|
-
alias :on_native :on_unsupported
|
|
118
123
|
alias :on_intersect :on_unsupported
|
|
119
124
|
alias :on_subset :on_unsupported
|
|
120
125
|
alias :on_superset :on_unsupported
|
data/lib/predicate/version.rb
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
class Predicate
|
|
3
|
+
describe Predicate, "to_hashes" do
|
|
4
|
+
|
|
5
|
+
let(:p){ Predicate }
|
|
6
|
+
|
|
7
|
+
subject{ predicate.to_hashes }
|
|
8
|
+
|
|
9
|
+
context "tautology" do
|
|
10
|
+
let(:predicate){ Predicate.tautology }
|
|
11
|
+
|
|
12
|
+
it{ expect(subject).to eql([{},{}]) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context "contradiction" do
|
|
16
|
+
let(:predicate){ Predicate.contradiction }
|
|
17
|
+
|
|
18
|
+
it{ expect{ subject }.to raise_error(ArgumentError) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "eq" do
|
|
22
|
+
let(:predicate){ Predicate.eq(:x, 2) }
|
|
23
|
+
|
|
24
|
+
it{ expect(subject).to eql([{x: 2}, {}]) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "neq" do
|
|
28
|
+
let(:predicate){ Predicate.neq(:x, 2) }
|
|
29
|
+
|
|
30
|
+
it{ expect(subject).to eql([{},{x: 2}]) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "in" do
|
|
34
|
+
let(:predicate){ Predicate.in(:x, [2,3]) }
|
|
35
|
+
|
|
36
|
+
it{ expect(subject).to eql([{x: [2,3]},{}]) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "and" do
|
|
40
|
+
let(:predicate){ Predicate.eq(:x, 3) & Predicate.in(:y, [2,3]) }
|
|
41
|
+
|
|
42
|
+
it{ expect(subject).to eql([{x: 3, y: [2,3]},{}]) }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "and with a neq" do
|
|
46
|
+
let(:predicate){ Predicate.neq(:x, 3) & Predicate.in(:y, [2,3]) }
|
|
47
|
+
|
|
48
|
+
it{ expect(subject).to eql([{y: [2,3]},{x: 3}]) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "not nil & eq" do
|
|
52
|
+
let(:predicate){ Predicate.neq(:x, nil) & Predicate.eq(:x, [2,3]) }
|
|
53
|
+
|
|
54
|
+
it{ expect(subject).to eql([{x: [2,3]},{x: nil}]) }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
## unsupported
|
|
58
|
+
|
|
59
|
+
context "not" do
|
|
60
|
+
let(:predicate){ Predicate.not(Predicate.eq(:x, 2)) }
|
|
61
|
+
|
|
62
|
+
it{ expect{ subject }.to raise_error(ArgumentError) }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "not-and" do
|
|
66
|
+
let(:predicate){ Predicate.not(Predicate.eq(:x, 3) & Predicate.in(:y, [2,3])) }
|
|
67
|
+
|
|
68
|
+
it{ expect{ subject }.to raise_error(ArgumentError) }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -101,21 +101,6 @@ class Predicate
|
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
context 'in with something responding to sql_literal' do
|
|
105
|
-
let(:operand){
|
|
106
|
-
Object.new.tap{|o|
|
|
107
|
-
def o.sql_literal(db)
|
|
108
|
-
"Hello World"
|
|
109
|
-
end
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
let(:predicate) { Predicate.in(:price, Predicate.opaque(operand)) }
|
|
113
|
-
|
|
114
|
-
it 'works as expected' do
|
|
115
|
-
expect(subject).to eql("SELECT * FROM `items` WHERE (`price` IN (Hello World))")
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
104
|
context 'not' do
|
|
120
105
|
let(:predicate) { !Predicate.in(:price, [10.0, 17.99]) }
|
|
121
106
|
|
|
@@ -220,5 +205,43 @@ class Predicate
|
|
|
220
205
|
expect { subject }.to raise_error(NotSupportedError)
|
|
221
206
|
end
|
|
222
207
|
end
|
|
208
|
+
|
|
209
|
+
class SqlAble
|
|
210
|
+
def initialize(value)
|
|
211
|
+
@value = value
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def sql(*args, &bl)
|
|
215
|
+
@value
|
|
216
|
+
end
|
|
217
|
+
alias :sql_literal :sql
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
context 'opaque in an IN' do
|
|
221
|
+
let(:operand) {
|
|
222
|
+
SqlAble.new('Hello World')
|
|
223
|
+
}
|
|
224
|
+
let(:predicate) {
|
|
225
|
+
Predicate.in(:price, Predicate.opaque(operand))
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
it 'works as expected' do
|
|
229
|
+
expect(subject).to eql("SELECT * FROM `items` WHERE (`price` IN (Hello World))")
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
context 'native' do
|
|
234
|
+
let(:operand) {
|
|
235
|
+
SqlAble.new(Sequel.lit("1=1"))
|
|
236
|
+
}
|
|
237
|
+
let(:predicate) {
|
|
238
|
+
Predicate.native(operand)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
it 'works as expected' do
|
|
242
|
+
expect(subject).to eql("SELECT * FROM `items` WHERE (1=1)")
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
223
246
|
end
|
|
224
247
|
end
|
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.10.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: 2026-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sexpr
|
|
@@ -251,6 +251,7 @@ files:
|
|
|
251
251
|
- spec/predicate/test_rename.rb
|
|
252
252
|
- spec/predicate/test_tautology.rb
|
|
253
253
|
- spec/predicate/test_to_hash.rb
|
|
254
|
+
- spec/predicate/test_to_hashes.rb
|
|
254
255
|
- spec/predicate/test_to_s.rb
|
|
255
256
|
- spec/predicate/test_unqualify.rb
|
|
256
257
|
- spec/sequel/test_to_sequel.rb
|