supernova 0.6.3 → 0.6.4
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.
- data/VERSION +1 -1
- data/lib/supernova/condition.rb +18 -10
- data/spec/supernova/condition_spec.rb +18 -2
- data/supernova.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.4
|
data/lib/supernova/condition.rb
CHANGED
@@ -10,26 +10,34 @@ class Supernova::Condition
|
|
10
10
|
case type
|
11
11
|
when :not, :ne
|
12
12
|
if value.nil?
|
13
|
-
|
13
|
+
nil_filter
|
14
14
|
else
|
15
|
-
"!#{
|
15
|
+
"!#{key}:#{value}"
|
16
16
|
end
|
17
17
|
when :gt
|
18
|
-
"#{
|
18
|
+
"#{key}:{#{value} TO *}"
|
19
19
|
when :gte
|
20
|
-
"#{
|
20
|
+
"#{key}:[#{value} TO *]"
|
21
21
|
when :lt
|
22
|
-
"#{
|
22
|
+
"#{key}:{* TO #{value}}"
|
23
23
|
when :lte
|
24
|
-
"#{
|
24
|
+
"#{key}:[* TO #{value}]"
|
25
25
|
when :nin
|
26
|
-
"!(#{or_key_and_value(
|
26
|
+
value.is_a?(Range) ? "#{key}:{* TO #{value.first}} OR #{key}:{#{value.last} TO *}" : "!(#{or_key_and_value(value)})"
|
27
27
|
when :in
|
28
|
-
or_key_and_value(
|
28
|
+
or_key_and_value(value)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
32
|
+
def nil_filter
|
33
|
+
"#{key}:[* TO *]"
|
34
|
+
end
|
35
|
+
|
36
|
+
def or_key_and_value(values)
|
37
|
+
if values.is_a?(Range)
|
38
|
+
"#{key}:[#{values.first} TO #{values.last}]"
|
39
|
+
else
|
40
|
+
values.map { |v| v.nil? ? "!#{nil_filter}" : "#{key}:#{v}"}.join(" OR ")
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
@@ -16,12 +16,28 @@ describe "Supernova::Condition" do
|
|
16
16
|
:user_id.ne.solr_filter_for(7).should == "!user_id:7"
|
17
17
|
end
|
18
18
|
|
19
|
+
it "returns the correct filter for in" do
|
20
|
+
:user_id.in.solr_filter_for([1, 2, 3]).should == "user_id:1 OR user_id:2 OR user_id:3"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the correct filter for in when ranges are used" do
|
24
|
+
:user_id.in.solr_filter_for(Range.new(1, 3)).should == "user_id:[1 TO 3]"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns the correct filter for in when nil is in array" do
|
28
|
+
:user_id.in.solr_filter_for([1, 2, nil]).should == "user_id:1 OR user_id:2 OR !user_id:[* TO *]"
|
29
|
+
end
|
30
|
+
|
19
31
|
it "returns the correct filter for nin" do
|
20
32
|
:user_id.nin.solr_filter_for([1, 2, 3]).should == "!(user_id:1 OR user_id:2 OR user_id:3)"
|
21
33
|
end
|
22
34
|
|
23
|
-
it "returns the correct filter for nin" do
|
24
|
-
:user_id.
|
35
|
+
it "returns the correct filter for nin when ranges are used" do
|
36
|
+
:user_id.nin.solr_filter_for(Range.new(1, 3)).should == "user_id:{* TO 1} OR user_id:{3 TO *}"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the correct filter for nin when nil is in array" do
|
40
|
+
:user_id.nin.solr_filter_for([1, 2, nil]).should == "!(user_id:1 OR user_id:2 OR !user_id:[* TO *])"
|
25
41
|
end
|
26
42
|
|
27
43
|
it "returns the correct filter for not nil" do
|
data/supernova.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: supernova
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 4
|
10
|
+
version: 0.6.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Schwab
|