wherewolf 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -61,7 +61,7 @@ For a real-life, running example, check out: http://wherewolf.herokuapp.com/
61
61
  player = Player.where_query('name ~= "Peter%"')
62
62
  # Returns all players who's name starts with Peter
63
63
 
64
- As you can see, where_query returns an ARel object, so you chain other statements to it. Please note, though: at the moment where_query needs to be the first in the chain.
64
+ As you can see, where_query returns an ARel object, so you chain other statements to it.
65
65
 
66
66
  == Order
67
67
 
@@ -79,6 +79,10 @@ You can also supply an order_query to handle ordering
79
79
  player = Player.order_query("name desc, position desc")
80
80
  # You can also have multiple order columns
81
81
 
82
+ Of course you can nest them...
83
+
84
+ player = Player.where_query("first_cap != null").order_query('name desc')
85
+
82
86
  == Errors
83
87
 
84
88
  At the moment, error handling is very primitive. Just capture
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.4.0"
25
+ gem.version = "0.4.1"
26
26
  # dependencies defined in Gemfile
27
27
  end
28
28
  Jeweler::RubygemsDotOrgTasks.new
@@ -12,17 +12,10 @@ module Wherewolf
12
12
 
13
13
  module ClassMethods
14
14
  def has_query_parsing(options = {})
15
- self.extend QueryMethods
16
- end
17
- end
18
-
19
- module QueryMethods
20
- def where_query(query)
21
- Wherewolf::Where::Processor.parse(self, query)
22
- end
23
-
24
- def order_query(query)
25
- Wherewolf::Order::Processor.parse(self, query)
15
+ self.class_eval do
16
+ scope :where_query, lambda { |query| Wherewolf::Where::Processor.parse(self, query) }
17
+ scope :order_query, lambda { |query| Wherewolf::Order::Processor.parse(self, query) }
18
+ end
26
19
  end
27
20
  end
28
21
  end
@@ -2,6 +2,11 @@ require 'helper'
2
2
 
3
3
  class RailtieTest < Test::Unit::TestCase
4
4
  context 'Railtie' do
5
+ setup do
6
+ setup_database
7
+ setup_fixtures
8
+ end
9
+
5
10
  should 'not enable where_query if has_query_parsing is not called' do
6
11
  assert_equal false, Team.respond_to?(:where_query)
7
12
  end
@@ -9,5 +14,20 @@ class RailtieTest < Test::Unit::TestCase
9
14
  should 'enable where_query if has_query_parsing is called' do
10
15
  assert_equal true, Player.respond_to?(:where_query)
11
16
  end
17
+
18
+ should 'not enable order_query if has_query_parsing is not called' do
19
+ assert_equal false, Team.respond_to?(:order_query)
20
+ end
21
+
22
+ should 'enable order_query if has_query_parsing is called' do
23
+ assert_equal true, Player.respond_to?(:order_query)
24
+ end
25
+
26
+ should 'allow where_query and order_query to be nestable' do
27
+ assert_nothing_raised do
28
+ players = Player.where_query('active = true').order_query('name desc')
29
+ assert_equal Player.where('active = ?', true).order('name desc').map(&:id), players.map(&:id)
30
+ end
31
+ end
12
32
  end
13
33
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wherewolf"
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
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-11"
12
+ s.date = "2012-10-12"
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 = [
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
45
45
  s.homepage = "http://github.com/madpilot/wherewolf"
46
46
  s.licenses = ["MIT"]
47
47
  s.require_paths = ["lib"]
48
- s.rubygems_version = "1.8.24"
48
+ s.rubygems_version = "1.8.15"
49
49
  s.summary = "Makes filtering and searching to your REST API crazy easy."
50
50
 
51
51
  if s.respond_to? :specification_version then
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.4.0
4
+ version: 0.4.1
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-11 00:00:00.000000000 Z
12
+ date: 2012-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arel
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70304497147180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *70304497147180
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: parslet
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70304497162220 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *70304497162220
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: shoulda
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70304497160940 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *70304497160940
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: rdoc
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70304497159820 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0'
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *70304497159820
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: bundler
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70304497158780 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ! '>='
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: '0'
86
66
  type: :development
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
68
+ version_requirements: *70304497158780
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: jeweler
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &70304497157580 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ! '>='
@@ -101,15 +76,10 @@ dependencies:
101
76
  version: '0'
102
77
  type: :development
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
79
+ version_requirements: *70304497157580
110
80
  - !ruby/object:Gem::Dependency
111
81
  name: guard
112
- requirement: !ruby/object:Gem::Requirement
82
+ requirement: &70304497458900 !ruby/object:Gem::Requirement
113
83
  none: false
114
84
  requirements:
115
85
  - - ! '>='
@@ -117,15 +87,10 @@ dependencies:
117
87
  version: '0'
118
88
  type: :development
119
89
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
90
+ version_requirements: *70304497458900
126
91
  - !ruby/object:Gem::Dependency
127
92
  name: guard-test
128
- requirement: !ruby/object:Gem::Requirement
93
+ requirement: &70304497457480 !ruby/object:Gem::Requirement
129
94
  none: false
130
95
  requirements:
131
96
  - - ! '>='
@@ -133,15 +98,10 @@ dependencies:
133
98
  version: '0'
134
99
  type: :development
135
100
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
101
+ version_requirements: *70304497457480
142
102
  - !ruby/object:Gem::Dependency
143
103
  name: simplecov
144
- requirement: !ruby/object:Gem::Requirement
104
+ requirement: &70304497455240 !ruby/object:Gem::Requirement
145
105
  none: false
146
106
  requirements:
147
107
  - - ! '>='
@@ -149,15 +109,10 @@ dependencies:
149
109
  version: '0'
150
110
  type: :development
151
111
  prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
112
+ version_requirements: *70304497455240
158
113
  - !ruby/object:Gem::Dependency
159
114
  name: sqlite3
160
- requirement: !ruby/object:Gem::Requirement
115
+ requirement: &70304497453700 !ruby/object:Gem::Requirement
161
116
  none: false
162
117
  requirements:
163
118
  - - ! '>='
@@ -165,15 +120,10 @@ dependencies:
165
120
  version: '0'
166
121
  type: :development
167
122
  prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
123
+ version_requirements: *70304497453700
174
124
  - !ruby/object:Gem::Dependency
175
125
  name: rails
176
- requirement: !ruby/object:Gem::Requirement
126
+ requirement: &70304497452400 !ruby/object:Gem::Requirement
177
127
  none: false
178
128
  requirements:
179
129
  - - ! '>='
@@ -181,15 +131,10 @@ dependencies:
181
131
  version: '0'
182
132
  type: :development
183
133
  prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
187
- - - ! '>='
188
- - !ruby/object:Gem::Version
189
- version: '0'
134
+ version_requirements: *70304497452400
190
135
  - !ruby/object:Gem::Dependency
191
136
  name: mocha
192
- requirement: !ruby/object:Gem::Requirement
137
+ requirement: &70304497451180 !ruby/object:Gem::Requirement
193
138
  none: false
194
139
  requirements:
195
140
  - - ! '>='
@@ -197,12 +142,7 @@ dependencies:
197
142
  version: '0'
198
143
  type: :development
199
144
  prerelease: false
200
- version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
- requirements:
203
- - - ! '>='
204
- - !ruby/object:Gem::Version
205
- version: '0'
145
+ version_requirements: *70304497451180
206
146
  description: Wherewolf allows you to consume search terms as strings without worrying
207
147
  about database injections. It parses the query and converts it into ARel. It's great
208
148
  for creating filterable REST APIs.
@@ -252,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
192
  version: '0'
253
193
  segments:
254
194
  - 0
255
- hash: 3659032346363356481
195
+ hash: -548541850773955983
256
196
  required_rubygems_version: !ruby/object:Gem::Requirement
257
197
  none: false
258
198
  requirements:
@@ -261,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
201
  version: '0'
262
202
  requirements: []
263
203
  rubyforge_project:
264
- rubygems_version: 1.8.24
204
+ rubygems_version: 1.8.15
265
205
  signing_key:
266
206
  specification_version: 3
267
207
  summary: Makes filtering and searching to your REST API crazy easy.