wherewolf 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - rbx-18mode
5
+ - rbx-19mode
6
+ - 1.8.7
7
+
8
+ env:
9
+ - RAILS_VERSION=""
10
+ - RAILS_VERSION="~>3.2.0"
11
+ - RAILS_VERSION="~>3.1.0"
12
+ - RAILS_VERSION="~>3.0.0"
data/Gemfile CHANGED
@@ -4,14 +4,18 @@ gem "arel"
4
4
  gem "parslet"
5
5
 
6
6
  group :development do
7
- gem "shoulda"
8
- gem "rdoc"
9
- gem "bundler"
7
+ gem "simplecov", :require => false
10
8
  gem "jeweler"
9
+ gem "bundler"
10
+ gem "rdoc"
11
11
  gem "guard"
12
12
  gem "guard-test"
13
- gem "simplecov", :require => false
13
+ end
14
+
15
+ group :test do
16
+ gem "shoulda"
14
17
  gem "sqlite3"
15
18
  gem "rails"
16
19
  gem "mocha"
20
+ gem "rake"
17
21
  end
data/Gemfile.lock CHANGED
@@ -130,6 +130,7 @@ DEPENDENCIES
130
130
  mocha
131
131
  parslet
132
132
  rails
133
+ rake
133
134
  rdoc
134
135
  shoulda
135
136
  simplecov
@@ -1,8 +1,8 @@
1
- = wherewolf
1
+ # wherewolf [![Build Status](https://secure.travis-ci.org/madpilot/wherewolf.png)](http://travis-ci.org/madpilot/wherewolf)
2
2
 
3
3
  Makes adding filtering and searching to your REST API crazy easy.
4
4
 
5
- == Problem
5
+ ## Problem
6
6
 
7
7
  Most RESTful APIs expose a "/index" endpoint that return all of objects at a given endpoint. That is fine until you need the ability to filter them.
8
8
 
@@ -28,7 +28,7 @@ Ok, it doesn't read amazingly, but this is an API, so encoding that stuff is tri
28
28
 
29
29
  Wherewolf will take that string and converts it in to ARel, so your clients can run arbitary queries against your API.
30
30
 
31
- == Get started
31
+ ## Get started
32
32
 
33
33
  The easiest way is to use Bundler:
34
34
 
@@ -36,9 +36,11 @@ The easiest way is to use Bundler:
36
36
 
37
37
  Then for every model that you want to by queryable, do this:
38
38
 
39
- class Player < ActiveRecord::Base
40
- has_query_parsing
41
- end
39
+ ```ruby
40
+ class Player < ActiveRecord::Base
41
+ has_query_parsing
42
+ end
43
+ ```
42
44
 
43
45
  This will add the "where_query" and "order_query" methods, which you pass your query string in to.
44
46
 
@@ -46,78 +48,92 @@ has_query_parsing can take two options: whitelist and blacklist which allow you
46
48
 
47
49
  Setting whitelist will mean ONLY those columns will be searchable
48
50
 
49
- class Player < ActiveRecord::Base
50
- has_query_parsing :whitelist => [ :name ] # Only name will be searchable
51
- end
51
+ ```ruby
52
+ class Player < ActiveRecord::Base
53
+ has_query_parsing :whitelist => [ :name ] # Only name will be searchable
54
+ end
52
55
 
53
56
  Setting blacklist will remove those columns from the list
54
57
 
55
- class Player < ActiveRecord::Base
56
- has_query_parsing :blacklist => [ :name ] # Name will not be searchable
57
- end
58
+ class Player < ActiveRecord::Base
59
+ has_query_parsing :blacklist => [ :name ] # Name will not be searchable
60
+ end
61
+ ```
58
62
 
59
63
  Both whitelist and blacklist can take a proc if you want to lazy evaluate
60
64
 
61
- class Player < ActiveRecord::Base
62
- has_query_parsing :whitelist => proc { |model| model.accessible_attributes.map(&:to_sym) }
63
- end
65
+ ```ruby
66
+ class Player < ActiveRecord::Base
67
+ has_query_parsing :whitelist => proc { |model| model.accessible_attributes.map(&:to_sym) }
68
+ end
69
+ ```
64
70
 
65
71
  would restrict the searchable columns to those exposed by accessible_attributes
66
72
 
67
- == Example
73
+ ## Example
68
74
 
69
75
  For a real-life, running example, check out: http://wherewolf.herokuapp.com/
70
76
 
71
- player = Player.where_query("(position = wing || position = lock) && first_cap < 1905-01-01").order('first_cap')
72
- # Returns all players that play 'wing' or 'lock', and played before 1905-01-01
77
+ ```ruby
78
+ player = Player.where_query("(position = wing || position = lock) && first_cap < 1905-01-01").order('first_cap')
79
+ # Returns all players that play 'wing' or 'lock', and played before 1905-01-01
73
80
 
74
- player = Player.where_query('name = "John Eales"')
75
- # Returns all players names 'John Eales'
81
+ player = Player.where_query('name = "John Eales"')
82
+ # Returns all players names 'John Eales'
76
83
 
77
- player = Player.where_query("first_cap >= 1905-01-01 && active = false")
78
- # Returns all inactitve players that played after 1905-01-01.
84
+ player = Player.where_query("first_cap >= 1905-01-01 && active = false")
85
+ # Returns all inactitve players that played after 1905-01-01.
79
86
 
80
- player = Player.where_query("first_cap != null")
81
- # Returns all players who have received their first cap (ie first_cap is NOT nil)
82
-
83
- player = Player.where_query('name ~= "Peter%"')
84
- # Returns all players who's name starts with Peter
87
+ player = Player.where_query("first_cap != null")
88
+ # Returns all players who have received their first cap (ie first_cap is NOT nil)
89
+
90
+ player = Player.where_query('name ~= "Peter%"')
91
+ # Returns all players who's name starts with Peter
92
+ ```
85
93
 
86
94
  As you can see, where_query returns an ARel object, so you chain other statements to it.
87
95
 
88
- == Order
96
+ ## Order
89
97
 
90
98
  You can also supply an order_query to handle ordering
91
99
 
92
- player = Player.order_query("name asc")
93
- # Order by name asc
94
-
95
- player = Player.order_query("name desc")
96
- # Order by name desc
97
-
98
- player = Player.order_query("name")
99
- # By default ordering is ascending
100
+ ```ruby
101
+ player = Player.order_query("name asc")
102
+ # Order by name asc
103
+
104
+ player = Player.order_query("name desc")
105
+ # Order by name desc
106
+
107
+ player = Player.order_query("name")
108
+ # By default ordering is ascending
100
109
 
101
- player = Player.order_query("name desc, position desc")
102
- # You can also have multiple order columns
110
+ player = Player.order_query("name desc, position desc")
111
+ # You can also have multiple order columns
112
+ ```
103
113
 
104
114
  Of course, you can nest them...
105
115
 
106
- player = Player.where_query("first_cap != null").order_query('name desc')
116
+ ```ruby
117
+ player = Player.where_query("first_cap != null").order_query('name desc')
118
+ ```
107
119
 
108
- == Errors
120
+ ## Errors
109
121
 
110
122
  At the moment, error handling is very primitive. Just capture
111
123
 
112
- Wherewolf::ParseError
124
+ ```ruby
125
+ Wherewolf::ParseError
126
+ ```
113
127
 
114
128
  You can print out a simple error message like so
115
129
 
116
- begin
117
- Player.where_query('name ~= "Patrick%" || (position = "fail)')
118
- rescue Wherewolf::ParseError => e
119
- puts e.error_message
120
- end
130
+ ```ruby
131
+ begin
132
+ Player.where_query('name ~= "Patrick%" || (position = "fail)')
133
+ rescue Wherewolf::ParseError => e
134
+ puts e.error_message
135
+ end
136
+ ```
121
137
 
122
138
  Will print out
123
139
 
@@ -125,13 +141,15 @@ Will print out
125
141
 
126
142
  You can get the character number by:
127
143
 
128
- begin
129
- Player.where_query('name ~= "Patrick%" || (position = "fail)')
130
- rescue Wherewolf::ParseError => e
131
- e.position # This value will be 28
132
- end
144
+ ```ruby
145
+ begin
146
+ Player.where_query('name ~= "Patrick%" || (position = "fail)')
147
+ rescue Wherewolf::ParseError => e
148
+ e.position # This value will be 28
149
+ end
150
+ ```
133
151
 
134
- == To Do
152
+ ## To Do
135
153
 
136
154
  * Better error messages (Give a clue as to why parsing failed)
137
155
  * Aliases such for operators, such as 'and', 'or' etc
@@ -139,7 +157,7 @@ You can get the character number by:
139
157
  * More edge case testing
140
158
  * Ability to call named scopes
141
159
 
142
- == Contributing to wherewolf
160
+ ## Contributing to wherewolf
143
161
 
144
162
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
145
163
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -149,7 +167,6 @@ You can get the character number by:
149
167
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
150
168
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
151
169
 
152
- == Copyright
170
+ ## Copyright
153
171
 
154
- Copyright (c) 2012 Myles Eftos. See LICENSE.txt for
155
- further details.
172
+ Copyright (c) 2012 [MadPilot Productions](http://www.madpilot.com.au/). See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ Jeweler::Tasks.new do |gem|
22
22
  gem.description = %Q{Wherewolf allows you to consume search terms as strings without worrying about database injections. It parses the query and converts it into ARel. It's great for creating filterable REST APIs.}
23
23
  gem.email = "myles@madpilot.com.au"
24
24
  gem.authors = ["Myles Eftos"]
25
- gem.version = "0.6.0"
25
+ gem.version = "0.7.0"
26
26
  # dependencies defined in Gemfile
27
27
  end
28
28
  Jeweler::RubygemsDotOrgTasks.new
@@ -20,16 +20,16 @@ module Wherewolf
20
20
 
21
21
  def process(ast, table)
22
22
  operation = ast.keys.first
23
- self.send("process_#{operation}".to_sym, ast[operation], table) if self.respond_to?("process_#{operation}".to_sym)
23
+ self.send("process_#{operation}".to_sym, ast[operation], table) if self.respond_to?("process_#{operation}".to_sym, true)
24
24
  end
25
25
 
26
26
  protected
27
27
  def process_and(ast, table)
28
- process(ast[:left], table).and(process(ast[:right], table))
28
+ process(ast[:left], table).and(process(ast[:right], table))
29
29
  end
30
30
 
31
31
  def process_or(ast, table)
32
- process(ast[:left], table).or(process(ast[:right], table))
32
+ process(ast[:left], table).or(process(ast[:right], table))
33
33
  end
34
34
 
35
35
  def process_eq(ast, table)
data/wherewolf.gemspec CHANGED
@@ -5,24 +5,25 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wherewolf"
8
- s.version = "0.6.0"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Myles Eftos"]
12
- s.date = "2012-10-12"
12
+ s.date = "2013-08-16"
13
13
  s.description = "Wherewolf allows you to consume search terms as strings without worrying about database injections. It parses the query and converts it into ARel. It's great for creating filterable REST APIs."
14
14
  s.email = "myles@madpilot.com.au"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README.rdoc"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".travis.yml",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
23
24
  "Guardfile",
24
25
  "LICENSE.txt",
25
- "README.rdoc",
26
+ "README.md",
26
27
  "Rakefile",
27
28
  "lib/wherewolf.rb",
28
29
  "lib/wherewolf/order/parser.rb",
@@ -54,43 +55,31 @@ Gem::Specification.new do |s|
54
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
56
  s.add_runtime_dependency(%q<arel>, [">= 0"])
56
57
  s.add_runtime_dependency(%q<parslet>, [">= 0"])
57
- s.add_development_dependency(%q<shoulda>, [">= 0"])
58
- s.add_development_dependency(%q<rdoc>, [">= 0"])
59
- s.add_development_dependency(%q<bundler>, [">= 0"])
58
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
60
59
  s.add_development_dependency(%q<jeweler>, [">= 0"])
60
+ s.add_development_dependency(%q<bundler>, [">= 0"])
61
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
61
62
  s.add_development_dependency(%q<guard>, [">= 0"])
62
63
  s.add_development_dependency(%q<guard-test>, [">= 0"])
63
- s.add_development_dependency(%q<simplecov>, [">= 0"])
64
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
65
- s.add_development_dependency(%q<rails>, [">= 0"])
66
- s.add_development_dependency(%q<mocha>, [">= 0"])
67
64
  else
68
65
  s.add_dependency(%q<arel>, [">= 0"])
69
66
  s.add_dependency(%q<parslet>, [">= 0"])
70
- s.add_dependency(%q<shoulda>, [">= 0"])
71
- s.add_dependency(%q<rdoc>, [">= 0"])
72
- s.add_dependency(%q<bundler>, [">= 0"])
67
+ s.add_dependency(%q<simplecov>, [">= 0"])
73
68
  s.add_dependency(%q<jeweler>, [">= 0"])
69
+ s.add_dependency(%q<bundler>, [">= 0"])
70
+ s.add_dependency(%q<rdoc>, [">= 0"])
74
71
  s.add_dependency(%q<guard>, [">= 0"])
75
72
  s.add_dependency(%q<guard-test>, [">= 0"])
76
- s.add_dependency(%q<simplecov>, [">= 0"])
77
- s.add_dependency(%q<sqlite3>, [">= 0"])
78
- s.add_dependency(%q<rails>, [">= 0"])
79
- s.add_dependency(%q<mocha>, [">= 0"])
80
73
  end
81
74
  else
82
75
  s.add_dependency(%q<arel>, [">= 0"])
83
76
  s.add_dependency(%q<parslet>, [">= 0"])
84
- s.add_dependency(%q<shoulda>, [">= 0"])
85
- s.add_dependency(%q<rdoc>, [">= 0"])
86
- s.add_dependency(%q<bundler>, [">= 0"])
77
+ s.add_dependency(%q<simplecov>, [">= 0"])
87
78
  s.add_dependency(%q<jeweler>, [">= 0"])
79
+ s.add_dependency(%q<bundler>, [">= 0"])
80
+ s.add_dependency(%q<rdoc>, [">= 0"])
88
81
  s.add_dependency(%q<guard>, [">= 0"])
89
82
  s.add_dependency(%q<guard-test>, [">= 0"])
90
- s.add_dependency(%q<simplecov>, [">= 0"])
91
- s.add_dependency(%q<sqlite3>, [">= 0"])
92
- s.add_dependency(%q<rails>, [">= 0"])
93
- s.add_dependency(%q<mocha>, [">= 0"])
94
83
  end
95
84
  end
96
85
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wherewolf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-12 00:00:00.000000000 Z
12
+ date: 2013-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arel
16
- requirement: &70363111528740 !ruby/object:Gem::Requirement
16
+ requirement: &70230414498620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70363111528740
24
+ version_requirements: *70230414498620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: parslet
27
- requirement: &70363111528260 !ruby/object:Gem::Requirement
27
+ requirement: &70230414497280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70363111528260
35
+ version_requirements: *70230414497280
36
36
  - !ruby/object:Gem::Dependency
37
- name: shoulda
38
- requirement: &70363111527780 !ruby/object:Gem::Requirement
37
+ name: simplecov
38
+ requirement: &70230414496000 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70363111527780
46
+ version_requirements: *70230414496000
47
47
  - !ruby/object:Gem::Dependency
48
- name: rdoc
49
- requirement: &70363111527300 !ruby/object:Gem::Requirement
48
+ name: jeweler
49
+ requirement: &70230414495000 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70363111527300
57
+ version_requirements: *70230414495000
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &70363111526820 !ruby/object:Gem::Requirement
60
+ requirement: &70230414494320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70363111526820
68
+ version_requirements: *70230414494320
69
69
  - !ruby/object:Gem::Dependency
70
- name: jeweler
71
- requirement: &70363111526340 !ruby/object:Gem::Requirement
70
+ name: rdoc
71
+ requirement: &70230414493480 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70363111526340
79
+ version_requirements: *70230414493480
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard
82
- requirement: &70363111525860 !ruby/object:Gem::Requirement
82
+ requirement: &70230414526800 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,54 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70363111525860
90
+ version_requirements: *70230414526800
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-test
93
- requirement: &70363111525380 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- type: :development
100
- prerelease: false
101
- version_requirements: *70363111525380
102
- - !ruby/object:Gem::Dependency
103
- name: simplecov
104
- requirement: &70363111524900 !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: *70363111524900
113
- - !ruby/object:Gem::Dependency
114
- name: sqlite3
115
- requirement: &70363111524420 !ruby/object:Gem::Requirement
116
- none: false
117
- requirements:
118
- - - ! '>='
119
- - !ruby/object:Gem::Version
120
- version: '0'
121
- type: :development
122
- prerelease: false
123
- version_requirements: *70363111524420
124
- - !ruby/object:Gem::Dependency
125
- name: rails
126
- requirement: &70363126234820 !ruby/object:Gem::Requirement
127
- none: false
128
- requirements:
129
- - - ! '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: *70363126234820
135
- - !ruby/object:Gem::Dependency
136
- name: mocha
137
- requirement: &70363126233820 !ruby/object:Gem::Requirement
93
+ requirement: &70230414526240 !ruby/object:Gem::Requirement
138
94
  none: false
139
95
  requirements:
140
96
  - - ! '>='
@@ -142,7 +98,7 @@ dependencies:
142
98
  version: '0'
143
99
  type: :development
144
100
  prerelease: false
145
- version_requirements: *70363126233820
101
+ version_requirements: *70230414526240
146
102
  description: Wherewolf allows you to consume search terms as strings without worrying
147
103
  about database injections. It parses the query and converts it into ARel. It's great
148
104
  for creating filterable REST APIs.
@@ -151,14 +107,15 @@ executables: []
151
107
  extensions: []
152
108
  extra_rdoc_files:
153
109
  - LICENSE.txt
154
- - README.rdoc
110
+ - README.md
155
111
  files:
156
112
  - .document
113
+ - .travis.yml
157
114
  - Gemfile
158
115
  - Gemfile.lock
159
116
  - Guardfile
160
117
  - LICENSE.txt
161
- - README.rdoc
118
+ - README.md
162
119
  - Rakefile
163
120
  - lib/wherewolf.rb
164
121
  - lib/wherewolf/order/parser.rb
@@ -192,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
149
  version: '0'
193
150
  segments:
194
151
  - 0
195
- hash: -3222849472552349803
152
+ hash: 2295607200233817462
196
153
  required_rubygems_version: !ruby/object:Gem::Requirement
197
154
  none: false
198
155
  requirements: