where_conditioner 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/where_conditioner.rb +3 -3
- data/spec/lib/where_conditioner_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4413174ed2b12c678a7961447406a1af1bc9be81
|
4
|
+
data.tar.gz: 5daab752c7324355971f1847001096273a02fd08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0549831f127959ebaaf0fc2be5da7e730c9546ea8c35f2a2591a280f9c24cc7b497818d9cb1cbdab715c5f8b94983f110dc2c27d6deecee130fba37ffb7eb64
|
7
|
+
data.tar.gz: 92eb7f6550cd9023da4a7279aaf910c2b3cdb374e00cfee6599de3f5586ca0e4cb61de1a203350396613a1d6e11fde4d031a15ed240571d53e8d25dc8b640cf3
|
data/lib/where_conditioner.rb
CHANGED
@@ -25,9 +25,9 @@ module WhereConditioner
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def elsif condition, &block
|
28
|
-
|
29
|
-
@last_condition
|
30
|
-
|
28
|
+
condition &&= !@last_condition # falsify condition if an "if" or "elsif" branch has already succeeded
|
29
|
+
@last_condition ||= condition # @last_condition is true if at least one branch has succeeded, including this elsif
|
30
|
+
conditional condition, &block
|
31
31
|
end
|
32
32
|
|
33
33
|
def where_if_present *args
|
@@ -169,6 +169,22 @@ describe WhereConditioner do
|
|
169
169
|
relation.if(true).foo.elsif(false).bar.baz
|
170
170
|
end
|
171
171
|
end
|
172
|
+
|
173
|
+
context 'with multiple elsifs' do
|
174
|
+
it 'passes method calls to relation' do
|
175
|
+
expect(relation).to receive(:foo).and_return(relation)
|
176
|
+
expect(relation).to receive(:bar)
|
177
|
+
relation.if(true).foo.elsif(false).bad.elsif(true).other_bad.else.really_bad.bar
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'with an else clause' do
|
182
|
+
it 'passes method calls to relation' do
|
183
|
+
expect(relation).to receive(:foo).and_return(relation)
|
184
|
+
expect(relation).to receive(:bar)
|
185
|
+
relation.if(true).foo.elsif(false).bad.elsif(false).other_bad.else.really_bad.bar
|
186
|
+
end
|
187
|
+
end
|
172
188
|
end
|
173
189
|
|
174
190
|
context 'with a block' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: where_conditioner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Novak
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|