predicate 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d3a81672181d7e3403108a8f09f7d7adbb94266c
4
- data.tar.gz: ce94a0e1580ea4d77d177926a5e305736b47741b
2
+ SHA256:
3
+ metadata.gz: 6f717f6bf0c4cddf18b0a7762f6a85dd47200ec21c274fb974755319862420f1
4
+ data.tar.gz: 48ce7004023d6121f650ab05d9893c2d25ff3a60324450b773ec4629e643b752
5
5
  SHA512:
6
- metadata.gz: cd1126d3e88102910c26ff3181d9eb842e697b90632f82012c74efbd391a922de6465653ba9968ae802e8968cb8723f1e88fd30d0c630289c8ef6ef1fc86b97a
7
- data.tar.gz: b0e52017a78b5a33b9eeb7d62c1e6e08ca2090555a501b21d4407c991cedde6201926c8f2c6d40d5621d7d912935d00584675ab7257ebed62ce197054e5888d1
6
+ metadata.gz: eb29761546c30faca593aa4dd5749367fce9e3a3d85404a49d32db310c73471a9008b01f046828070583cb043f3142e1e10688be06a2a5dca4d318c144b1f33a
7
+ data.tar.gz: d8852634d7c9d33199544fa2ee0ef70f92198b379d6f7e6ed670d40266e8799e7ff7d804551cb1bcaf19c4b6390715217e665e8a03b4c50a5213be10c3e3c626
@@ -94,6 +94,10 @@ class Predicate
94
94
  expr.evaluate(tuple)
95
95
  end
96
96
 
97
+ def call(tuple)
98
+ expr.evaluate(tuple)
99
+ end
100
+
97
101
  # Splits this predicate, say P, as too predicates P1 & P2
98
102
  # such that `P <=> P1 & P2` and P2 makes no reference to
99
103
  # any attribute in `attr_list`.
@@ -48,7 +48,19 @@ class Predicate
48
48
  def on_in(sexpr)
49
49
  left, right = apply(sexpr.identifier), sexpr.right
50
50
  if right.literal?
51
- ::Sequel.expr(left => right.value)
51
+ values = Array(right.value).uniq
52
+ if values.include?(nil)
53
+ nonnil = values.compact
54
+ if nonnil.empty?
55
+ ::Sequel.expr(left => nil)
56
+ elsif nonnil.size == 1
57
+ ::Sequel.expr(left => nil) | ::Sequel.expr(left => nonnil.first)
58
+ else
59
+ ::Sequel.expr(left => nil) | ::Sequel.expr(left => nonnil)
60
+ end
61
+ else
62
+ ::Sequel.expr(left => right.value)
63
+ end
52
64
  elsif right.opaque?
53
65
  ::Sequel.expr(left => apply(right))
54
66
  else
@@ -1,7 +1,7 @@
1
1
  class Predicate
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 1
4
+ MINOR = 2
5
5
  TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
@@ -216,5 +216,14 @@ class Predicate
216
216
  end
217
217
  end
218
218
 
219
+ context 'has a call alias' do
220
+ let(:predicate){
221
+ Predicate.new(Factory.gte(:x => 0))
222
+ }
223
+
224
+ let(:scope){ { x: 2 } }
225
+
226
+ it{ expect(predicate.call(scope)).to be(true) }
227
+ end
219
228
  end
220
229
  end
@@ -85,6 +85,30 @@ class Predicate
85
85
  end
86
86
  end
87
87
 
88
+ context 'in with nil among values' do
89
+ let(:predicate) { Predicate.in(:price, [nil, 10.0, 17.99]) }
90
+
91
+ it 'works as expected' do
92
+ expect(subject).to eql("SELECT * FROM `items` WHERE ((`price` IS NULL) OR (`price` IN (10.0, 17.99)))")
93
+ end
94
+ end
95
+
96
+ context 'in with nil among values that can be simplified' do
97
+ let(:predicate) { Predicate.in(:price, [nil, 17.99]) }
98
+
99
+ it 'works as expected' do
100
+ expect(subject).to eql("SELECT * FROM `items` WHERE ((`price` IS NULL) OR (`price` = 17.99))")
101
+ end
102
+ end
103
+
104
+ context 'in with only nil among values ' do
105
+ let(:predicate) { Predicate.in(:price, [nil]) }
106
+
107
+ it 'works as expected' do
108
+ expect(subject).to eql("SELECT * FROM `items` WHERE (`price` IS NULL)")
109
+ end
110
+ end
111
+
88
112
  context 'in with something responding to sql_literal' do
89
113
  let(:operand){
90
114
  Object.new.tap{|o|
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.1.0
4
+ version: 2.2.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: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2019-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sexpr
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  version: '0'
205
205
  requirements: []
206
206
  rubyforge_project:
207
- rubygems_version: 2.5.2
207
+ rubygems_version: 2.7.6
208
208
  signing_key:
209
209
  specification_version: 4
210
210
  summary: Predicate provides a simple class and processors to encode and manipulate