query_string_filter 0.1.2 → 0.1.3
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/filter.treetop +7 -7
- data/query_string_filter.gemspec +2 -2
- data/spec/query_string_filter_spec.rb +24 -16
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/filter.treetop
CHANGED
@@ -8,7 +8,7 @@ grammar Filter
|
|
8
8
|
key ospace ':' ospace strings
|
9
9
|
{
|
10
10
|
def eval
|
11
|
-
{ key.eval
|
11
|
+
{ key.eval => /#{strings.eval}/ }
|
12
12
|
end
|
13
13
|
}
|
14
14
|
end
|
@@ -17,7 +17,7 @@ grammar Filter
|
|
17
17
|
key ospace '=' ospace value
|
18
18
|
{
|
19
19
|
def eval
|
20
|
-
{ key.eval
|
20
|
+
{ key.eval => value.eval }
|
21
21
|
end
|
22
22
|
}
|
23
23
|
end
|
@@ -30,7 +30,7 @@ grammar Filter
|
|
30
30
|
key ospace '>' ospace value
|
31
31
|
{
|
32
32
|
def eval
|
33
|
-
{ key.eval
|
33
|
+
{ key.eval => { '$gt' => value.eval } }
|
34
34
|
end
|
35
35
|
}
|
36
36
|
end
|
@@ -39,7 +39,7 @@ grammar Filter
|
|
39
39
|
key ospace '>=' ospace value
|
40
40
|
{
|
41
41
|
def eval
|
42
|
-
{ key.eval
|
42
|
+
{ key.eval => { '$gte' => value.eval } }
|
43
43
|
end
|
44
44
|
}
|
45
45
|
end
|
@@ -48,7 +48,7 @@ grammar Filter
|
|
48
48
|
key ospace '<' ospace value
|
49
49
|
{
|
50
50
|
def eval
|
51
|
-
{ key.eval
|
51
|
+
{ key.eval => { '$lt' => value.eval } }
|
52
52
|
end
|
53
53
|
}
|
54
54
|
end
|
@@ -57,13 +57,13 @@ grammar Filter
|
|
57
57
|
key ospace '<=' ospace value
|
58
58
|
{
|
59
59
|
def eval
|
60
|
-
{ key.eval
|
60
|
+
{ key.eval => { '$lte' => value.eval } }
|
61
61
|
end
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
65
65
|
rule key
|
66
|
-
[a-z_]+
|
66
|
+
[a-z_\.]+
|
67
67
|
{
|
68
68
|
def eval
|
69
69
|
text_value
|
data/query_string_filter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{query_string_filter}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David James"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-15}
|
13
13
|
s.description = %q{Convert a filter param in a query string to a conditions hash useful for MongoMapper searching}
|
14
14
|
s.email = %q{djames@sunlightfoundation.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,21 +21,29 @@ describe "QueryStringFilter" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "keys" do
|
24
|
-
it "
|
24
|
+
it "with underscore" do
|
25
25
|
@filter.parse("with_underscore = test").should == {
|
26
|
-
|
26
|
+
"with_underscore" => "test"
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
|
-
it "
|
30
|
+
it "with period" do
|
31
|
+
@filter.parse("released.year = 2008").should == {
|
32
|
+
'released.year' => 2008
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "values" do
|
38
|
+
it "with single quotes" do
|
31
39
|
@filter.parse("foo = 'bar camp'").should == {
|
32
|
-
|
40
|
+
"foo" => "bar camp"
|
33
41
|
}
|
34
42
|
end
|
35
43
|
|
36
|
-
it "
|
44
|
+
it "with http://" do
|
37
45
|
@filter.parse("url = http://cnn.com").should == {
|
38
|
-
|
46
|
+
"url" => "http://cnn.com"
|
39
47
|
}
|
40
48
|
end
|
41
49
|
end
|
@@ -43,7 +51,7 @@ describe "QueryStringFilter" do
|
|
43
51
|
describe "basic operators" do
|
44
52
|
it ": with string" do
|
45
53
|
expected = {
|
46
|
-
|
54
|
+
"name" => /david/
|
47
55
|
}
|
48
56
|
["name:david", "name : david"].each do |s|
|
49
57
|
@filter.parse(s).should == expected
|
@@ -51,7 +59,7 @@ describe "QueryStringFilter" do
|
|
51
59
|
end
|
52
60
|
|
53
61
|
it ": with number" do
|
54
|
-
expected = {
|
62
|
+
expected = { "count" => /77/ }
|
55
63
|
["count:77", "count : 77"].each do |s|
|
56
64
|
@filter.parse(s).should == expected
|
57
65
|
end
|
@@ -59,7 +67,7 @@ describe "QueryStringFilter" do
|
|
59
67
|
|
60
68
|
it "= with string" do
|
61
69
|
expected = {
|
62
|
-
|
70
|
+
"name" => "David"
|
63
71
|
}
|
64
72
|
[
|
65
73
|
%(name=David),
|
@@ -68,30 +76,30 @@ describe "QueryStringFilter" do
|
|
68
76
|
@filter.parse(s).should == expected
|
69
77
|
end
|
70
78
|
end
|
71
|
-
|
79
|
+
|
72
80
|
it ">" do
|
73
|
-
expected = {
|
81
|
+
expected = { "value" => { '$gt' => 12 } }
|
74
82
|
["value>12", "value > 12"].each do |s|
|
75
83
|
@filter.parse(s).should == expected
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|
79
87
|
it "<" do
|
80
|
-
expected = {
|
88
|
+
expected = { "value" => { '$lt' => 12 } }
|
81
89
|
["value<12", "value < 12"].each do |s|
|
82
90
|
@filter.parse(s).should == expected
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
86
94
|
it ">=" do
|
87
|
-
expected = {
|
95
|
+
expected = { "value" => { '$gte' => 12 } }
|
88
96
|
["value>=12", "value >= 12"].each do |s|
|
89
97
|
@filter.parse(s).should == expected
|
90
98
|
end
|
91
99
|
end
|
92
100
|
|
93
101
|
it "<=" do
|
94
|
-
expected = {
|
102
|
+
expected = { "value" => { '$lte' => 12 } }
|
95
103
|
["value<=12", "value <= 12"].each do |s|
|
96
104
|
@filter.parse(s).should == expected
|
97
105
|
end
|
@@ -101,7 +109,7 @@ describe "QueryStringFilter" do
|
|
101
109
|
describe "compound" do
|
102
110
|
it ": with 2 strings" do
|
103
111
|
expected = {
|
104
|
-
|
112
|
+
"title" => /election|texas/
|
105
113
|
}
|
106
114
|
[
|
107
115
|
"title:election,texas",
|
@@ -113,7 +121,7 @@ describe "QueryStringFilter" do
|
|
113
121
|
|
114
122
|
it ": with 3 strings" do
|
115
123
|
expected = {
|
116
|
-
|
124
|
+
"title" => /election|texas|bob/
|
117
125
|
}
|
118
126
|
[
|
119
127
|
"title:election,texas,bob",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_string_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David James
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-15 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|