query_string_filter 0.1.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David James
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = query_string_filter
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 David James. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "query_string_filter"
8
+ gem.summary = %Q{Convert from a filter query string param to a MongoMapper conditions hash}
9
+ gem.description = %Q{Convert a filter param in a query string to a conditions hash useful for MongoMapper searching}
10
+ gem.email = "djames@sunlightfoundation.com"
11
+ gem.homepage = "http://github.com/djsun/query_string_filter"
12
+ gem.authors = ["David James"]
13
+ gem.add_dependency('treetop', '>= 1.4.2')
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "query_string_filter #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,117 @@
1
+ grammar Filter
2
+
3
+ rule match
4
+ fuzzy / equality / inequality
5
+ end
6
+
7
+ rule fuzzy
8
+ key ospace ':' ospace strings
9
+ {
10
+ def eval
11
+ { key.eval.intern => /#{strings.eval}/ }
12
+ end
13
+ }
14
+ end
15
+
16
+ rule equality
17
+ key ospace '=' ospace value
18
+ {
19
+ def eval
20
+ { key.eval.intern => value.eval }
21
+ end
22
+ }
23
+ end
24
+
25
+ rule inequality
26
+ gt / gte / lt / lte
27
+ end
28
+
29
+ rule gt
30
+ key ospace '>' ospace value
31
+ {
32
+ def eval
33
+ { key.eval.intern => { '$gt' => value.eval } }
34
+ end
35
+ }
36
+ end
37
+
38
+ rule gte
39
+ key ospace '>=' ospace value
40
+ {
41
+ def eval
42
+ { key.eval.intern => { '$gte' => value.eval } }
43
+ end
44
+ }
45
+ end
46
+
47
+ rule lt
48
+ key ospace '<' ospace value
49
+ {
50
+ def eval
51
+ { key.eval.intern => { '$lt' => value.eval } }
52
+ end
53
+ }
54
+ end
55
+
56
+ rule lte
57
+ key ospace '<=' ospace value
58
+ {
59
+ def eval
60
+ { key.eval.intern => { '$lte' => value.eval } }
61
+ end
62
+ }
63
+ end
64
+
65
+ rule key
66
+ [a-z]+
67
+ {
68
+ def eval
69
+ text_value
70
+ end
71
+ }
72
+ end
73
+
74
+ rule value
75
+ integer / string
76
+ end
77
+
78
+ rule strings
79
+ string more:(ospace ',' ospace string)*
80
+ {
81
+ def eval
82
+ strings.map { |e| e.eval }.join("|")
83
+ end
84
+
85
+ def strings
86
+ [string] + more.elements.map { |e| e.string }
87
+ end
88
+ }
89
+ end
90
+
91
+ rule string
92
+ [A-Z_a-z0-9]+
93
+ {
94
+ def eval
95
+ text_value
96
+ end
97
+ }
98
+ end
99
+
100
+ rule integer
101
+ [0-9]+
102
+ {
103
+ def eval
104
+ text_value.to_i
105
+ end
106
+ }
107
+ end
108
+
109
+ rule ospace
110
+ ' '*
111
+ end
112
+
113
+ rule space
114
+ ' '+
115
+ end
116
+
117
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'treetop'
3
+ Treetop.load(File.dirname(__FILE__) + '/filter')
4
+
5
+ class QueryStringFilter
6
+
7
+ def initialize
8
+ @parser = FilterParser.new
9
+ end
10
+
11
+ def process(string)
12
+ @parser.parse(string).eval
13
+ end
14
+
15
+ end
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{query_string_filter}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David James"]
12
+ s.date = %q{2009-10-27}
13
+ s.description = %q{TODO: longer description of your gem}
14
+ s.email = %q{djames@sunlightfoundation.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/filter.treetop",
27
+ "lib/query_string_filter.rb",
28
+ "query_string_filter.gemspec",
29
+ "spec/query_string_filter_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/djsun/query_string_filter}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{TODO: one-line summary of your gem}
38
+ s.test_files = [
39
+ "spec/query_string_filter_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<treetop>, [">= 1.4.2"])
49
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
50
+ else
51
+ s.add_dependency(%q<treetop>, [">= 1.4.2"])
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<treetop>, [">= 1.4.2"])
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ end
58
+ end
59
+
@@ -0,0 +1,84 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "QueryStringFilter" do
4
+
5
+ before do
6
+ @filter = QueryStringFilter.new
7
+ end
8
+
9
+ describe "basic" do
10
+
11
+ it ": with string" do
12
+ expected = {
13
+ :name => /david/
14
+ }
15
+ ["name:david", "name : david"].each do |s|
16
+ @filter.process(s).should == expected
17
+ end
18
+ end
19
+
20
+ it ": with number" do
21
+ expected = { :count => /77/ }
22
+ ["count:77", "count : 77"].each do |s|
23
+ @filter.process(s).should == expected
24
+ end
25
+ end
26
+
27
+ it ">" do
28
+ expected = { :value => { '$gt' => 12 } }
29
+ ["value>12", "value > 12"].each do |s|
30
+ @filter.process(s).should == expected
31
+ end
32
+ end
33
+
34
+ it "<" do
35
+ expected = { :value => { '$lt' => 12 } }
36
+ ["value<12", "value < 12"].each do |s|
37
+ @filter.process(s).should == expected
38
+ end
39
+ end
40
+
41
+ it ">=" do
42
+ expected = { :value => { '$gte' => 12 } }
43
+ ["value>=12", "value >= 12"].each do |s|
44
+ @filter.process(s).should == expected
45
+ end
46
+ end
47
+
48
+ it "<=" do
49
+ expected = { :value => { '$lte' => 12 } }
50
+ ["value<=12", "value <= 12"].each do |s|
51
+ @filter.process(s).should == expected
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ describe "compound" do
58
+
59
+ it ": with 2 strings" do
60
+ expected = {
61
+ :title => /election|texas/
62
+ }
63
+ [
64
+ "title:election,texas",
65
+ "title : election , texas"
66
+ ].each do |s|
67
+ @filter.process(s).should == expected
68
+ end
69
+ end
70
+
71
+ it ": with 3 strings" do
72
+ expected = {
73
+ :title => /election|texas|bob/
74
+ }
75
+ [
76
+ "title:election,texas,bob",
77
+ ].each do |s|
78
+ @filter.process(s).should == expected
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'query_string_filter'
4
+
5
+ require 'rubygems'
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: query_string_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David James
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-27 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: treetop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ version:
35
+ description: Convert a filter param in a query string to a conditions hash useful for MongoMapper searching
36
+ email: djames@sunlightfoundation.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/filter.treetop
52
+ - lib/query_string_filter.rb
53
+ - query_string_filter.gemspec
54
+ - spec/query_string_filter_spec.rb
55
+ - spec/spec.opts
56
+ - spec/spec_helper.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/djsun/query_string_filter
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.5
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Convert from a filter query string param to a MongoMapper conditions hash
85
+ test_files:
86
+ - spec/query_string_filter_spec.rb
87
+ - spec/spec_helper.rb