will_filter 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- will_filter (3.1.5)
4
+ will_filter (3.1.6)
5
5
  coffee-script
6
6
  kaminari
7
7
  rails (>= 3.1.0)
@@ -31,7 +31,7 @@ module WillFilter
31
31
  #############################################################################
32
32
  # Basics
33
33
  #############################################################################
34
- def initialize(model_class)
34
+ def initialize(model_class = nil)
35
35
  super()
36
36
 
37
37
  if WillFilter::Config.require_filter_extensions? and self.class.name == "WillFilter::Filter"
@@ -94,8 +94,16 @@ module WillFilter
94
94
  []
95
95
  end
96
96
 
97
+ # For extra security, this method must be overloaded by the extending class.
97
98
  def model_class
98
- return nil unless model_class_name
99
+ if WillFilter::Config.require_filter_extensions?
100
+ raise WillFilter::FilterException.new("model_class method must be overloaded in the extending class.")
101
+ end
102
+
103
+ if model_class_name.blank?
104
+ raise WillFilter::FilterException.new("model_class_name was not specified.")
105
+ end
106
+
99
107
  @model_class ||= model_class_name.constantize
100
108
  end
101
109
 
@@ -192,6 +200,8 @@ module WillFilter
192
200
 
193
201
  def order
194
202
  @order ||= default_order
203
+ @order = default_order unless contains_column?(@order.to_sym)
204
+ @order
195
205
  end
196
206
 
197
207
  def default_order_type
@@ -200,6 +210,8 @@ module WillFilter
200
210
 
201
211
  def order_type
202
212
  @order_type ||= default_order_type
213
+ @order_type = default_order_type unless ['asc', 'desc'].include?(@order_type.to_s)
214
+ @order_type
203
215
  end
204
216
 
205
217
  def order_clause
@@ -385,14 +397,27 @@ module WillFilter
385
397
  params = HashWithIndifferentAccess.new(params) unless params.is_a?(HashWithIndifferentAccess)
386
398
 
387
399
  params[:wf_type] = self.name unless params[:wf_type]
388
- params[:wf_type].constantize.new(params[:wf_model]).deserialize_from_params(params)
400
+ filter_class = params[:wf_type].constantize
401
+ filter_instance = filter_class.new
402
+
403
+ unless filter_instance.kind_of?(WillFilter::Filter)
404
+ raise WillFilter::FilterException.new("Invalid filter class. Filter classes must extand WillFilter::Filter.")
405
+ end
406
+
407
+ if WillFilter::Config.require_filter_extensions?
408
+ filter_instance.deserialize_from_params(params)
409
+ else
410
+ filter_class.new(params[:wf_model]).deserialize_from_params(params)
411
+ end
389
412
  end
390
413
 
391
414
  def deserialize_from_params(params)
392
415
  params = HashWithIndifferentAccess.new(params) unless params.is_a?(HashWithIndifferentAccess)
416
+
393
417
  @conditions = []
394
418
  @match = params[:wf_match] || :all
395
419
  @key = params[:wf_key] || self.id.to_s
420
+
396
421
  self.model_class_name = params[:wf_model] if params[:wf_model]
397
422
 
398
423
  @per_page = params[:wf_per_page] || default_per_page
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module WillFilter
25
- VERSION = "3.1.5"
25
+ VERSION = "3.1.6"
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2152808640 !ruby/object:Gem::Requirement
16
+ requirement: &2164951700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152808640
24
+ version_requirements: *2164951700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: kaminari
27
- requirement: &2152803760 !ruby/object:Gem::Requirement
27
+ requirement: &2164948000 !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: *2152803760
35
+ version_requirements: *2164948000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sass
38
- requirement: &2152801020 !ruby/object:Gem::Requirement
38
+ requirement: &2164944880 !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: :runtime
45
45
  prerelease: false
46
- version_requirements: *2152801020
46
+ version_requirements: *2164944880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-script
49
- requirement: &2152797920 !ruby/object:Gem::Requirement
49
+ requirement: &2164941460 !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: :runtime
56
56
  prerelease: false
57
- version_requirements: *2152797920
57
+ version_requirements: *2164941460
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &2152795980 !ruby/object:Gem::Requirement
60
+ requirement: &2164936460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2152795980
68
+ version_requirements: *2164936460
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &2152794840 !ruby/object:Gem::Requirement
71
+ requirement: &2164935220 !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: *2152794840
79
+ version_requirements: *2164935220
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2152794080 !ruby/object:Gem::Requirement
82
+ requirement: &2164933660 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2152794080
90
+ version_requirements: *2164933660
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec-rails
93
- requirement: &2152793280 !ruby/object:Gem::Requirement
93
+ requirement: &2164931900 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2152793280
101
+ version_requirements: *2164931900
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: factory_girl
104
- requirement: &2152792380 !ruby/object:Gem::Requirement
104
+ requirement: &2164861240 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2152792380
112
+ version_requirements: *2164861240
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rr
115
- requirement: &2152791540 !ruby/object:Gem::Requirement
115
+ requirement: &2164859840 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2152791540
123
+ version_requirements: *2164859840
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: steak
126
- requirement: &2152790380 !ruby/object:Gem::Requirement
126
+ requirement: &2164858760 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2152790380
134
+ version_requirements: *2164858760
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: capybara
137
- requirement: &2152789520 !ruby/object:Gem::Requirement
137
+ requirement: &2164857640 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2152789520
145
+ version_requirements: *2164857640
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: database_cleaner
148
- requirement: &2152788600 !ruby/object:Gem::Requirement
148
+ requirement: &2164856120 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *2152788600
156
+ version_requirements: *2164856120
157
157
  description: will_filter is a powerful customizable framework for filtering active_record
158
158
  models.
159
159
  email:
@@ -363,7 +363,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
363
363
  version: '0'
364
364
  segments:
365
365
  - 0
366
- hash: -4561456729773262300
366
+ hash: -509527631151697114
367
367
  required_rubygems_version: !ruby/object:Gem::Requirement
368
368
  none: false
369
369
  requirements:
@@ -372,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
372
372
  version: '0'
373
373
  segments:
374
374
  - 0
375
- hash: -4561456729773262300
375
+ hash: -509527631151697114
376
376
  requirements: []
377
377
  rubyforge_project: will_filter
378
378
  rubygems_version: 1.8.11