will_filter 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,6 +64,8 @@ module WillFilter
64
64
  end
65
65
 
66
66
  def save_filter
67
+ raise WillFilter::FilterException.new("Saving functions are disabled") unless WillFilter::Config.saving_enabled?
68
+
67
69
  params.delete(:wf_id)
68
70
 
69
71
  wf_filter = WillFilter::Filter.deserialize_from_params(params)
@@ -79,6 +81,8 @@ module WillFilter
79
81
  end
80
82
 
81
83
  def update_filter
84
+ raise WillFilter::FilterException.new("Saving functions are disabled") unless WillFilter::Config.saving_enabled?
85
+
82
86
  wf_filter = WillFilter::Filter.find_by_id(params.delete(:wf_id))
83
87
  wf_filter.deserialize_from_params(params)
84
88
  wf_filter.validate!
@@ -93,6 +97,8 @@ module WillFilter
93
97
  end
94
98
 
95
99
  def delete_filter
100
+ raise WillFilter::FilterException.new("Saving functions are disabled") unless WillFilter::Config.saving_enabled?
101
+
96
102
  wf_filter = WillFilter::Filter.find_by_id(params[:wf_id])
97
103
  wf_filter.destroy if wf_filter
98
104
 
@@ -31,8 +31,13 @@ module WillFilter
31
31
  #############################################################################
32
32
  # Basics
33
33
  #############################################################################
34
- def initialize(model_class)
34
+ def initialize(model_class = nil)
35
35
  super()
36
+
37
+ if WillFilter::Config.require_filter_extensions? and self.class.name == "WillFilter::Filter"
38
+ raise WillFilter::FilterException.new("Your configuration requires you to subclass the filter. Default filter cannot be created.")
39
+ end
40
+
36
41
  self.model_class_name = model_class.to_s
37
42
  end
38
43
 
@@ -89,8 +94,16 @@ module WillFilter
89
94
  []
90
95
  end
91
96
 
97
+ # For extra security, this method must be overloaded by the extending class.
92
98
  def model_class
93
- 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
+
94
107
  @model_class ||= model_class_name.constantize
95
108
  end
96
109
 
@@ -188,6 +201,8 @@ module WillFilter
188
201
 
189
202
  def order
190
203
  @order ||= default_order
204
+ @order = default_order unless contains_column?(@order.to_sym)
205
+ @order
191
206
  end
192
207
 
193
208
  def default_order_type
@@ -196,6 +211,8 @@ module WillFilter
196
211
 
197
212
  def order_type
198
213
  @order_type ||= default_order_type
214
+ @order_type = default_order_type unless ['asc', 'desc'].include?(@order_type.to_s)
215
+ @order_type
199
216
  end
200
217
 
201
218
  def order_clause
@@ -380,15 +397,30 @@ module WillFilter
380
397
  def self.deserialize_from_params(params)
381
398
  params = HashWithIndifferentAccess.new(params) unless params.is_a?(HashWithIndifferentAccess)
382
399
  params[:wf_type] = self.name unless params[:wf_type]
383
- 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
384
412
  end
385
413
 
386
414
  def deserialize_from_params(params)
387
415
  params = HashWithIndifferentAccess.new(params) unless params.is_a?(HashWithIndifferentAccess)
416
+
417
+ # Validate sanity of user provided parameters
418
+ params.delete(:wf_order_type) unless [ 'asc', 'desc' ].include? params[:wf_order_type]
419
+ params.delete(:wf_order) unless self.class.columns.map(&:name).include? params[:wf_order]
420
+
388
421
  @conditions = []
389
422
  @match = params[:wf_match] || :all
390
423
  @key = params[:wf_key] || self.id.to_s
391
- self.model_class_name = params[:wf_model] if params[:wf_model]
392
424
 
393
425
  @per_page = params[:wf_per_page] || default_per_page
394
426
  @page = params[:page] || 1
@@ -3,9 +3,12 @@
3
3
  <%= hidden_field_tag(:wf_dirty, "false") %>
4
4
  <%= hidden_field_tag(:wf_submitted, "false") %>
5
5
  <%= hidden_field_tag(:wf_name, wf_filter.name) %>
6
- <%= hidden_field_tag(:wf_model, wf_filter.model_class_name) %>
7
6
  <%= hidden_field_tag(:wf_export_format, "") %>
8
7
  <%= hidden_field_tag(:wf_export_fields, "") %>
8
+
9
+ <% unless WillFilter::Config.require_filter_extensions? %>
10
+ <%= hidden_field_tag(:wf_model, wf_filter.model_class_name) %>
11
+ <% end %>
9
12
 
10
13
  <div class="wf_header">
11
14
  <% if wf_filter.show_save_options? %>
@@ -23,7 +23,7 @@
23
23
 
24
24
  class ActiveRecord::Base
25
25
  def self.filter(opts = {})
26
- if ActiveRecord::Base == self.class
26
+ if 'ActiveRecord::Base' == self.to_s
27
27
  raise WillFilter::FilterException.new("Cannot apply filter to the ActiveRecord::Base object")
28
28
  end
29
29
 
@@ -10,6 +10,34 @@
10
10
  #############################################################################
11
11
 
12
12
  defaults: &defaults
13
+
14
+ ###########################################################################
15
+ #
16
+ # require_filter_extension makes the filter into an abstract class
17
+ # and will require you to subclass it in order for the filter to be
18
+ # serializeable. The following will no longer work:
19
+ #
20
+ # @users = User.filter(:params => params)
21
+ #
22
+ # Use your own filter class instead:
23
+ #
24
+ # @users = User.filter(:params => params, :filter => UserFilter)
25
+ #
26
+ # In the subclass you must provide the model name to be filtered by overloading:
27
+ #
28
+ # def model_class
29
+ # User
30
+ # end
31
+ #
32
+ ###########################################################################
33
+
34
+ require_filter_extensions: false
35
+
36
+ ###########################################################################
37
+ # If you would like to see some JavaScript effects
38
+ # provide your own effects class and implement required methods
39
+ ###########################################################################
40
+
13
41
  effects_options:
14
42
  enabled: false
15
43
  script_path: "/will_filter/javascripts/will_filter_prototype_effects.js"
@@ -45,6 +45,10 @@ module WillFilter
45
45
  @config ||= load_yml("/config/will_filter/config.yml")
46
46
  end
47
47
 
48
+ def self.require_filter_extensions?
49
+ config[:require_filter_extensions]
50
+ end
51
+
48
52
  def self.effects_options
49
53
  config[:effects_options]
50
54
  end
metadata CHANGED
@@ -1,75 +1,22 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: will_filter
3
- version: !ruby/object:Gem::Version
4
- hash: 1
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.4
5
5
  prerelease:
6
- segments:
7
- - 3
8
- - 0
9
- - 3
10
- version: 3.0.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Michael Berkovich
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-06-22 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :runtime
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- - 0
34
- version: 3.0.0
35
- name: rails
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- prerelease: false
39
- type: :runtime
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 1923831917
46
- segments:
47
- - 3
48
- - 0
49
- - pre
50
- - 2
51
- version: 3.0.pre2
52
- name: will_paginate
53
- version_requirements: *id002
54
- description: Rails engine for filtering ActiveRecord model objects.
55
- email: theiceberk@gmail.com
12
+ date: 2012-04-06 00:00:00.000000000Z
13
+ dependencies: []
14
+ description:
15
+ email:
56
16
  executables: []
57
-
58
17
  extensions: []
59
-
60
- extra_rdoc_files:
61
- - LICENSE
62
- - README.rdoc
63
- files:
64
- - .loadpath
65
- - .project
66
- - CHANGELOG.rdoc
67
- - Gemfile
68
- - Gemfile.lock
69
- - LICENSE
70
- - README.rdoc
71
- - Rakefile
72
- - VERSION
18
+ extra_rdoc_files: []
19
+ files:
73
20
  - app/controllers/application_controller.rb
74
21
  - app/controllers/will_filter/calendar_controller.rb
75
22
  - app/controllers/will_filter/exporter_controller.rb
@@ -99,7 +46,6 @@ files:
99
46
  - app/views/will_filter/filter/containers/_numeric_range.html.erb
100
47
  - app/views/will_filter/filter/containers/_text.html.erb
101
48
  - app/views/will_filter/filter/index.html.erb
102
- - config.ru
103
49
  - config/application.rb
104
50
  - config/boot.rb
105
51
  - config/database.yml
@@ -109,12 +55,22 @@ files:
109
55
  - config/environments/test.rb
110
56
  - config/routes.rb
111
57
  - config/will_filter/config.yml
112
- - db/development.sqlite3
113
- - db/migrate/20090730070119_create_will_filter_tables.rb
114
- - db/seeds.rb
115
- - db/test.sqlite3
116
- - doc/README_FOR_APP
117
- - examples/README
58
+ - public/404.html
59
+ - public/422.html
60
+ - public/500.html
61
+ - public/favicon.ico
62
+ - public/robots.txt
63
+ - public/will_filter/images/buttons.png
64
+ - public/will_filter/images/calendar.png
65
+ - public/will_filter/images/clock.png
66
+ - public/will_filter/images/close.gif
67
+ - public/will_filter/images/results_table_th_active.gif
68
+ - public/will_filter/images/sort_arrow_all.gif
69
+ - public/will_filter/images/sort_bg.gif
70
+ - public/will_filter/images/spinner.gif
71
+ - public/will_filter/javascripts/will_filter.js
72
+ - public/will_filter/javascripts/will_filter_prototype_effects.js
73
+ - public/will_filter/stylesheets/will_filter.css
118
74
  - lib/application_helper.rb
119
75
  - lib/core_ext/active_record/base.rb
120
76
  - lib/core_ext/array.rb
@@ -122,9 +78,7 @@ files:
122
78
  - lib/generators/will_filter/templates/config.yml
123
79
  - lib/generators/will_filter/templates/create_will_filter_tables.rb
124
80
  - lib/generators/will_filter/will_filter_generator.rb
125
- - lib/tasks/.gitkeep
126
81
  - lib/tasks/will_filter_tasks.rake
127
- - lib/will_filter.rb
128
82
  - lib/will_filter/calendar.rb
129
83
  - lib/will_filter/common_methods.rb
130
84
  - lib/will_filter/config.rb
@@ -146,63 +100,29 @@ files:
146
100
  - lib/will_filter/filter_condition.rb
147
101
  - lib/will_filter/filter_container.rb
148
102
  - lib/will_filter/filter_exception.rb
149
- - pkg/will_filter-0.1.0.gem
150
- - pkg/will_filter-0.1.1.gem
151
- - public/404.html
152
- - public/422.html
153
- - public/500.html
154
- - public/favicon.ico
155
- - public/robots.txt
156
- - public/will_filter/images/buttons.png
157
- - public/will_filter/images/calendar.png
158
- - public/will_filter/images/clock.png
159
- - public/will_filter/images/close.gif
160
- - public/will_filter/images/results_table_th_active.gif
161
- - public/will_filter/images/sort_arrow_all.gif
162
- - public/will_filter/images/sort_bg.gif
163
- - public/will_filter/images/spinner.gif
164
- - public/will_filter/javascripts/will_filter.js
165
- - public/will_filter/javascripts/will_filter_prototype_effects.js
166
- - public/will_filter/stylesheets/will_filter.css
167
- - script/rails
168
- - test/functional/models/will_filter/filter_test.rb
169
- - test/performance/browsing_test.rb
170
- - test/test_helper.rb
171
- - uninstall.rb
172
- - will_filter.gemspec
173
- has_rdoc: true
103
+ - lib/will_filter.rb
174
104
  homepage: http://github.com/berk/will_filter
175
105
  licenses: []
176
-
177
106
  post_install_message:
178
107
  rdoc_options: []
179
-
180
- require_paths:
108
+ require_paths:
181
109
  - lib
182
- required_ruby_version: !ruby/object:Gem::Requirement
110
+ required_ruby_version: !ruby/object:Gem::Requirement
183
111
  none: false
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- hash: 3
188
- segments:
189
- - 0
190
- version: "0"
191
- required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
117
  none: false
193
- requirements:
194
- - - ">="
195
- - !ruby/object:Gem::Version
196
- hash: 3
197
- segments:
198
- - 0
199
- version: "0"
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
200
122
  requirements: []
201
-
202
123
  rubyforge_project:
203
- rubygems_version: 1.6.2
124
+ rubygems_version: 1.8.11
204
125
  signing_key:
205
126
  specification_version: 3
206
127
  summary: Rails engine for filtering ActiveRecord model objects.
207
128
  test_files: []
208
-
data/.loadpath DELETED
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <loadpath>
3
- <pathentry path="" type="src"/>
4
- <pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
5
- <pathentry path="GEM_LIB/activerecord-2.3.2/lib" type="var"/>
6
- <pathentry path="GEM_LIB/rake-0.8.4/lib" type="var"/>
7
- <pathentry path="GEM_LIB/activeresource-2.3.2/lib" type="var"/>
8
- <pathentry path="GEM_LIB/rails-2.3.2/lib" type="var"/>
9
- <pathentry path="GEM_LIB/actionmailer-2.3.2/lib" type="var"/>
10
- <pathentry path="GEM_LIB/actionpack-2.3.2/lib" type="var"/>
11
- <pathentry path="GEM_LIB/activesupport-2.3.2/lib" type="var"/>
12
- </loadpath>
data/.project DELETED
@@ -1,18 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <projectDescription>
3
- <name>will_filter</name>
4
- <comment></comment>
5
- <projects>
6
- </projects>
7
- <buildSpec>
8
- <buildCommand>
9
- <name>org.rubypeople.rdt.core.rubybuilder</name>
10
- <arguments>
11
- </arguments>
12
- </buildCommand>
13
- </buildSpec>
14
- <natures>
15
- <nature>org.rubypeople.rdt.core.rubynature</nature>
16
- <nature>org.radrails.rails.core.railsnature</nature>
17
- </natures>
18
- </projectDescription>
data/CHANGELOG.rdoc DELETED
@@ -1 +0,0 @@
1
- == 0.1.0, released 2011-05-29
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'rails', '~> 3.0.0'
4
- gem "will_paginate", "~> 3.0.pre2"
5
-
6
- # gem 'sqlite3'
data/Gemfile.lock DELETED
@@ -1,73 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.7)
6
- actionpack (= 3.0.7)
7
- mail (~> 2.2.15)
8
- actionpack (3.0.7)
9
- activemodel (= 3.0.7)
10
- activesupport (= 3.0.7)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.5.0)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.14)
16
- rack-test (~> 0.5.7)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.7)
19
- activesupport (= 3.0.7)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.5.0)
22
- activerecord (3.0.7)
23
- activemodel (= 3.0.7)
24
- activesupport (= 3.0.7)
25
- arel (~> 2.0.2)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.7)
28
- activemodel (= 3.0.7)
29
- activesupport (= 3.0.7)
30
- activesupport (3.0.7)
31
- arel (2.0.10)
32
- builder (2.1.2)
33
- erubis (2.6.6)
34
- abstract (>= 1.0.0)
35
- i18n (0.5.0)
36
- mail (2.2.19)
37
- activesupport (>= 2.3.6)
38
- i18n (>= 0.4.0)
39
- mime-types (~> 1.16)
40
- treetop (~> 1.4.8)
41
- mime-types (1.16)
42
- polyglot (0.3.1)
43
- rack (1.2.3)
44
- rack-mount (0.6.14)
45
- rack (>= 1.0.0)
46
- rack-test (0.5.7)
47
- rack (>= 1.0)
48
- rails (3.0.7)
49
- actionmailer (= 3.0.7)
50
- actionpack (= 3.0.7)
51
- activerecord (= 3.0.7)
52
- activeresource (= 3.0.7)
53
- activesupport (= 3.0.7)
54
- bundler (~> 1.0)
55
- railties (= 3.0.7)
56
- railties (3.0.7)
57
- actionpack (= 3.0.7)
58
- activesupport (= 3.0.7)
59
- rake (>= 0.8.7)
60
- thor (~> 0.14.4)
61
- rake (0.9.1)
62
- thor (0.14.6)
63
- treetop (1.4.9)
64
- polyglot (>= 0.3.1)
65
- tzinfo (0.3.27)
66
- will_paginate (3.0.pre2)
67
-
68
- PLATFORMS
69
- ruby
70
-
71
- DEPENDENCIES
72
- rails (~> 3.0.0)
73
- will_paginate (~> 3.0.pre2)
data/LICENSE DELETED
@@ -1,18 +0,0 @@
1
- Copyright (c) 2011 Michael Berkovich
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
- the Software, and to permit persons to whom the Software is furnished to do so,
8
- subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc DELETED
@@ -1,74 +0,0 @@
1
- = WillFilter
2
-
3
- will_filter is a Rails engine plugin that extends the functionality of will_paginate by adding filters to your pages.
4
-
5
- == Preamble
6
-
7
- If you ever had to build an admin tool for your web site that displayed a list of objects that can be filtered using
8
- various criteria, this plugin will make your life easier. Adding a filtered page can now be
9
- a matter of adding two lines of code - one to your controller and one to your view. See examples below.
10
-
11
- For advanced samples of how to use the filters, please download and install the following project:
12
-
13
- http://github.com/berk/will_filter_examples
14
-
15
- == Installation Instructions
16
-
17
- Add the following gems to your Gemfile:
18
-
19
- gem "will_paginate", "~> 3.0.pre2"
20
- gem 'will_filter', "~> 3.0.0"
21
-
22
- And run:
23
-
24
- $ bundle install
25
-
26
- To configure and initialize will_filter engine, run the following commands:
27
-
28
- $ rails generate will_filter
29
- $ rake db:migrate
30
-
31
- == Examples
32
-
33
- To add a filtered result-set to your controller use the following method call:
34
-
35
- class OrderController < ApplicationController
36
-
37
- def index
38
- @orders = Order.filter(:params => params)
39
- end
40
-
41
- end
42
-
43
- Note: 'Order' is a Rails ActiveRecord model
44
-
45
- Now all you have to do is create a view for this action and add the following tag where you want the filter to be rendered:
46
-
47
- <%= will_filter(@orders) %>
48
-
49
- And optionally you can do (for results table):
50
-
51
- <%= will_filter_table_tag(@orders) %>
52
-
53
- That's it. This will render a filter box with various conditions, operators and values for the model object you selected.
54
-
55
- Below are a couple of screenshot of what the filter looks like when it is rendered on a page:
56
-
57
- http://wiki.tr8n.org/images/d/da/Will_filter_1.png
58
-
59
- http://wiki.tr8n.org/images/e/ec/Will_filter_2.png
60
-
61
- will_filter_examples project contains some samples that show you how to customize filters and much more
62
-
63
- git://github.com/berk/will_filter_examples.git
64
-
65
- Live will_filter_examples application is running here:
66
-
67
- http://wf.tr8n.org
68
-
69
- If you have any questions, comments or suggestions, email me at michael@geni.com
70
-
71
- == Authors and credits
72
-
73
- Authors:: Michael Berkovich
74
-
data/Rakefile DELETED
@@ -1,54 +0,0 @@
1
- #--
2
- # Copyright (c) 2011 Michael Berkovich
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- # Add your own tasks in files placed in lib/tasks ending in .rake,
25
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
26
-
27
- require 'rake/testtask'
28
-
29
- Rake::TestTask.new do |test|
30
- test.pattern = 'test/**/*_test.rb'
31
- test.libs << 'test'
32
- end
33
-
34
- begin
35
- require 'jeweler'
36
- Jeweler::Tasks.new do |s|
37
- s.name = "will_filter"
38
- s.summary = "Rails engine for filtering ActiveRecord model objects."
39
- s.email = "theiceberk@gmail.com"
40
- s.homepage = "http://github.com/berk/will_filter"
41
- s.description = "Rails engine for filtering ActiveRecord model objects."
42
- s.authors = ["Michael Berkovich"]
43
- end
44
- Jeweler::GemcutterTasks.new
45
- rescue LoadError
46
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
47
- end
48
-
49
- #require File.expand_path('../config/application', __FILE__)
50
- #require 'rake'
51
- #
52
- #WillFilter::Application.load_tasks
53
-
54
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 3.0.3
data/config.ru DELETED
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run WillFilter::Application
Binary file
@@ -1,19 +0,0 @@
1
- class CreateWillFilterTables < ActiveRecord::Migration
2
- def self.up
3
- create_table :wf_filters do |t|
4
- t.string :type
5
- t.string :name
6
- t.text :data
7
- t.integer :user_id
8
- t.string :model_class_name
9
-
10
- t.timestamps
11
- end
12
-
13
- add_index :wf_filters, [:user_id]
14
- end
15
-
16
- def self.down
17
- drop_table :wf_filters
18
- end
19
- end
data/db/seeds.rb DELETED
@@ -1,7 +0,0 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
- #
4
- # Examples:
5
- #
6
- # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
- # Mayor.create(:name => 'Daley', :city => cities.first)
data/db/test.sqlite3 DELETED
Binary file
data/doc/README_FOR_APP DELETED
@@ -1,2 +0,0 @@
1
- Use this README file to introduce your application and point to useful places in the API for learning more.
2
- Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
data/examples/README DELETED
@@ -1 +0,0 @@
1
- Please install will_filter_examples project to see how to configure the model_filters.
data/lib/tasks/.gitkeep DELETED
File without changes
Binary file
Binary file
data/script/rails DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
@@ -1,297 +0,0 @@
1
- require File.expand_path('../../../../test_helper', __FILE__)
2
-
3
- module WillFilter
4
- class FilterTest < ActiveSupport::TestCase
5
-
6
- test "boolean container" do
7
- params = {:wf_type=>"UserFilter",
8
- :wf_c0=>:admin,
9
- :wf_o0=>:is,
10
- :wf_v0_0=>"1"}
11
- filter = WillFilter::Filter.deserialize_from_params(params)
12
- assert_equal 1, filter.conditions.size
13
- assert_equal 2, filter.sql_conditions.size
14
- assert_equal " users.admin = ? ", filter.sql_conditions.first
15
- assert_equal true, filter.sql_conditions.last
16
-
17
- params = {:wf_type=>"UserFilter",
18
- :wf_c0=>:admin,
19
- :wf_o0=>:is,
20
- :wf_v0_0=>"0"}
21
- filter = WillFilter::Filter.deserialize_from_params(params)
22
- assert_equal 1, filter.conditions.size
23
- assert_equal 2, filter.sql_conditions.size
24
- assert_equal " users.admin = ? ", filter.sql_conditions.first
25
- assert_equal false, filter.sql_conditions.last
26
- end
27
-
28
- test "date range container" do
29
- params = {:wf_type=>"UserFilter",
30
- :wf_c0=>:birth_date,
31
- :wf_o0=>:is_in_the_range,
32
- :wf_v0_0=>"1971-11-09",
33
- :wf_v0_1=>"1974-11-09"}
34
- filter = WillFilter::Filter.deserialize_from_params(params)
35
- assert_equal 1, filter.conditions.size
36
- assert_equal 3, filter.sql_conditions.size
37
- assert_equal " (users.birth_date >= ? and users.birth_date <= ?) ", filter.sql_conditions.first
38
- end
39
-
40
- test "date time range container" do
41
- params = {:wf_type=>"UserFilter",
42
- :wf_c0=>:created_at,
43
- :wf_o0=>:is_in_the_range,
44
- :wf_v0_0=>"1971-11-09 8:00",
45
- :wf_v0_1=>"1971-11-09 12:00"}
46
- filter = WillFilter::Filter.deserialize_from_params(params)
47
- assert_equal 1, filter.conditions.size
48
- assert_equal 3, filter.sql_conditions.size
49
- assert_equal " (users.created_at >= ? and users.created_at <= ?) ", filter.sql_conditions.first
50
- end
51
-
52
- test "date time container" do
53
- params = {:wf_type=>"UserFilter",
54
- :wf_c0=>:created_at,
55
- :wf_o0=>:is,
56
- :wf_v0_0=>"1971-11-09 8:00"}
57
- filter = WillFilter::Filter.deserialize_from_params(params)
58
- assert_equal 1, filter.conditions.size
59
- assert_equal 2, filter.sql_conditions.size
60
- assert_equal " users.created_at = ? ", filter.sql_conditions.first
61
-
62
- params = {:wf_type=>"UserFilter",
63
- :wf_c0=>:created_at,
64
- :wf_o0=>:is_not,
65
- :wf_v0_0=>"1971-11-09 8:00"}
66
- filter = WillFilter::Filter.deserialize_from_params(params)
67
- assert_equal 1, filter.conditions.size
68
- assert_equal 2, filter.sql_conditions.size
69
- assert_equal " users.created_at <> ? ", filter.sql_conditions.first
70
-
71
- params = {:wf_type=>"UserFilter",
72
- :wf_c0=>:created_at,
73
- :wf_o0=>:is_after,
74
- :wf_v0_0=>"1971-11-09 8:00"}
75
- filter = WillFilter::Filter.deserialize_from_params(params)
76
- assert_equal 1, filter.conditions.size
77
- assert_equal 2, filter.sql_conditions.size
78
- assert_equal " users.created_at > ? ", filter.sql_conditions.first
79
-
80
- params = {:wf_type=>"UserFilter",
81
- :wf_c0=>:created_at,
82
- :wf_o0=>:is_before,
83
- :wf_v0_0=>"1971-11-09 8:00"}
84
- filter = WillFilter::Filter.deserialize_from_params(params)
85
- assert_equal 1, filter.conditions.size
86
- assert_equal 2, filter.sql_conditions.size
87
- assert_equal " users.created_at < ? ", filter.sql_conditions.first
88
- end
89
-
90
- test "date container" do
91
- params = {:wf_type=>"UserFilter",
92
- :wf_c0=>:birth_date,
93
- :wf_o0=>:is,
94
- :wf_v0_0=>"1971-11-09"}
95
- filter = WillFilter::Filter.deserialize_from_params(params)
96
- assert_equal 1, filter.conditions.size
97
- assert_equal 2, filter.sql_conditions.size
98
- assert_equal " users.birth_date = ? ", filter.sql_conditions.first
99
-
100
- params = {:wf_type=>"UserFilter",
101
- :wf_c0=>:birth_date,
102
- :wf_o0=>:is_not,
103
- :wf_v0_0=>"1971-11-09 8:00"}
104
- filter = WillFilter::Filter.deserialize_from_params(params)
105
- assert_equal 1, filter.conditions.size
106
- assert_equal 2, filter.sql_conditions.size
107
- assert_equal " users.birth_date <> ? ", filter.sql_conditions.first
108
-
109
- params = {:wf_type=>"UserFilter",
110
- :wf_c0=>:birth_date,
111
- :wf_o0=>:is_after,
112
- :wf_v0_0=>"1971-11-09 8:00"}
113
- filter = WillFilter::Filter.deserialize_from_params(params)
114
- assert_equal 1, filter.conditions.size
115
- assert_equal 2, filter.sql_conditions.size
116
- assert_equal " users.birth_date > ? ", filter.sql_conditions.first
117
-
118
- params = {:wf_type=>"UserFilter",
119
- :wf_c0=>:birth_date,
120
- :wf_o0=>:is_before,
121
- :wf_v0_0=>"1971-11-09 8:00"}
122
- filter = WillFilter::Filter.deserialize_from_params(params)
123
- assert_equal 1, filter.conditions.size
124
- assert_equal 2, filter.sql_conditions.size
125
- assert_equal " users.birth_date < ? ", filter.sql_conditions.first
126
- end
127
-
128
- test "numeric delimited container" do
129
- params = {:wf_type=>"UserFilter",
130
- :wf_c0=>:id,
131
- :wf_o0=>:is_in,
132
- :wf_v0_0=>"1,2,3,4,5,6"}
133
- filter = WillFilter::Filter.deserialize_from_params(params)
134
- assert_equal 1, filter.conditions.size
135
- assert_equal 2, filter.sql_conditions.size
136
- assert_equal " users.id in (?) ", filter.sql_conditions.first
137
- end
138
-
139
- test "numeric range container" do
140
- params = {:wf_type=>"UserFilter",
141
- :wf_c0=>:id,
142
- :wf_o0=>:is_in_the_range,
143
- :wf_v0_0=>"1",
144
- :wf_v0_1=>"10"}
145
- filter = WillFilter::Filter.deserialize_from_params(params)
146
- assert_equal 1, filter.conditions.size
147
- assert_equal 3, filter.sql_conditions.size
148
- assert_equal " (users.id >= ? and users.id <= ?) ", filter.sql_conditions.first
149
- end
150
-
151
- test "numeric container" do
152
- params = {:wf_type=>"UserFilter",
153
- :wf_c0=>:id,
154
- :wf_o0=>:is,
155
- :wf_v0_0=>"1"}
156
- filter = WillFilter::Filter.deserialize_from_params(params)
157
- assert_equal 1, filter.conditions.size
158
- assert_equal 2, filter.sql_conditions.size
159
- assert_equal " users.id = ? ", filter.sql_conditions.first
160
-
161
- params = {:wf_type=>"UserFilter",
162
- :wf_c0=>:id,
163
- :wf_o0=>:is_not,
164
- :wf_v0_0=>"1"}
165
- filter = WillFilter::Filter.deserialize_from_params(params)
166
- assert_equal 1, filter.conditions.size
167
- assert_equal 2, filter.sql_conditions.size
168
- assert_equal " users.id <> ? ", filter.sql_conditions.first
169
-
170
- params = {:wf_type=>"UserFilter",
171
- :wf_c0=>:id,
172
- :wf_o0=>:is_less_than,
173
- :wf_v0_0=>"1"}
174
- filter = WillFilter::Filter.deserialize_from_params(params)
175
- assert_equal 1, filter.conditions.size
176
- assert_equal 2, filter.sql_conditions.size
177
- assert_equal " users.id < ? ", filter.sql_conditions.first
178
-
179
- params = {:wf_type=>"UserFilter",
180
- :wf_c0=>:id,
181
- :wf_o0=>:is_greater_than,
182
- :wf_v0_0=>"1"}
183
- filter = WillFilter::Filter.deserialize_from_params(params)
184
- assert_equal 1, filter.conditions.size
185
- assert_equal 2, filter.sql_conditions.size
186
- assert_equal " users.id > ? ", filter.sql_conditions.first
187
- end
188
-
189
- test "single date container" do
190
- params = {:wf_type=>"UserFilter",
191
- :wf_c0=>:created_at,
192
- :wf_o0=>:is_on,
193
- :wf_v0_0=>"1971-11-09"}
194
- filter = WillFilter::Filter.deserialize_from_params(params)
195
- assert_equal 1, filter.conditions.size
196
- assert_equal 3, filter.sql_conditions.size
197
- assert_equal " users.created_at >= ? and users.created_at < ? ", filter.sql_conditions.first
198
-
199
- params = {:wf_type=>"UserFilter",
200
- :wf_c0=>:created_at,
201
- :wf_o0=>:is_not_on,
202
- :wf_v0_0=>"1971-11-09"}
203
- filter = WillFilter::Filter.deserialize_from_params(params)
204
- assert_equal 1, filter.conditions.size
205
- assert_equal 3, filter.sql_conditions.size
206
- assert_equal " users.created_at < ? and users.created_at >= ? ", filter.sql_conditions.first
207
- end
208
-
209
- test "text delimited container" do
210
- params = {:wf_type=>"UserFilter",
211
- :wf_c0=>:name,
212
- :wf_o0=>:is_in,
213
- :wf_v0_0=>"a,b,c,d,e,f,g"}
214
- filter = WillFilter::Filter.deserialize_from_params(params)
215
- assert_equal 1, filter.conditions.size
216
- assert_equal 2, filter.sql_conditions.size
217
- assert_equal " users.name in (?) ", filter.sql_conditions.first
218
-
219
- params = {:wf_type=>"UserFilter",
220
- :wf_c0=>:name,
221
- :wf_o0=>:is_not_in,
222
- :wf_v0_0=>"a,b,c,d,e,f,g"}
223
- filter = WillFilter::Filter.deserialize_from_params(params)
224
- assert_equal 1, filter.conditions.size
225
- assert_equal 2, filter.sql_conditions.size
226
- assert_equal " users.name not in (?) ", filter.sql_conditions.first
227
- end
228
-
229
- test "text container" do
230
- params = {:wf_type=>"UserFilter",
231
- :wf_c0=>:name,
232
- :wf_o0=>:is,
233
- :wf_v0_0=>"Mike"}
234
- filter = WillFilter::Filter.deserialize_from_params(params)
235
- assert_equal 2, filter.sql_conditions.size
236
- assert_equal " users.name = ? ", filter.sql_conditions.first
237
- assert_equal "Mike", filter.sql_conditions.last
238
-
239
- params = {:wf_type=>"UserFilter",
240
- :wf_c0=>:name,
241
- :wf_o0=>:is_not,
242
- :wf_v0_0=>"Mike"}
243
- filter = WillFilter::Filter.deserialize_from_params(params)
244
- assert_equal 2, filter.sql_conditions.size
245
- assert_equal " users.name <> ? ", filter.sql_conditions.first
246
-
247
- params = {:wf_type=>"UserFilter",
248
- :wf_c0=>:name,
249
- :wf_o0=>:contains,
250
- :wf_v0_0=>"Mike"}
251
- filter = WillFilter::Filter.deserialize_from_params(params)
252
- assert_equal 2, filter.sql_conditions.size
253
- assert_equal " users.name like ? ", filter.sql_conditions.first
254
-
255
- params = {:wf_type=>"UserFilter",
256
- :wf_c0=>:name,
257
- :wf_o0=>:does_not_contain,
258
- :wf_v0_0=>"Mike"}
259
- filter = WillFilter::Filter.deserialize_from_params(params)
260
- assert_equal 2, filter.sql_conditions.size
261
- assert_equal " users.name not like ? ", filter.sql_conditions.first
262
-
263
- params = {:wf_type=>"UserFilter",
264
- :wf_c0=>:name,
265
- :wf_o0=>:starts_with,
266
- :wf_v0_0=>"Mike"}
267
- filter = WillFilter::Filter.deserialize_from_params(params)
268
- assert_equal 2, filter.sql_conditions.size
269
- assert_equal " users.name like ? ", filter.sql_conditions.first
270
- assert_equal "Mike%", filter.sql_conditions.last
271
-
272
- params = {:wf_type=>"UserFilter",
273
- :wf_c0=>:name,
274
- :wf_o0=>:ends_with,
275
- :wf_v0_0=>"Mike"}
276
- filter = WillFilter::Filter.deserialize_from_params(params)
277
- assert_equal 2, filter.sql_conditions.size
278
- assert_equal " users.name like ? ", filter.sql_conditions.first
279
- assert_equal "%Mike", filter.sql_conditions.last
280
- end
281
-
282
- test "compound filter" do
283
- params = {:wf_type=>"UserFilter",
284
- :wf_c0=>:name,
285
- :wf_o0=>:is,
286
- :wf_v0_0=>"Mike",
287
- :wf_c1=>:birth_date,
288
- :wf_o1=>:is_before,
289
- :wf_v1_0=>"1971-11-09 8:00"
290
- }
291
- filter = WillFilter::Filter.deserialize_from_params(params)
292
- assert_equal 3, filter.sql_conditions.size
293
- assert_equal " users.name = ? AND users.birth_date < ? ", filter.sql_conditions.first
294
- end
295
-
296
- end
297
- end
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
- require 'rails/performance_test_help'
3
-
4
- # Profiling results for each test method are written to tmp/performance.
5
- class BrowsingTest < ActionDispatch::PerformanceTest
6
- def test_homepage
7
- get '/'
8
- end
9
- end
data/test/test_helper.rb DELETED
@@ -1,71 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path('../../config/environment', __FILE__)
3
- require 'rails/test_help'
4
-
5
- class ActiveSupport::TestCase
6
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
- #
8
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
- # -- they do not yet inherit this setting
10
- fixtures :all
11
-
12
- # Add more helper methods to be used by all tests here...
13
- end
14
-
15
- # Dummy UserFilter object for testing filter containers
16
- class UserFilter < WillFilter::Filter
17
- def table_name
18
- "users"
19
- end
20
-
21
- def definition
22
- {:id=>
23
- {:is_provided=>"nil",
24
- :is_not_provided=>"nil",
25
- :is=>"numeric",
26
- :is_not=>"numeric",
27
- :is_less_than=>"numeric",
28
- :is_greater_than=>"numeric",
29
- :is_in_the_range=>"numeric_range",
30
- :is_in=>"numeric_delimited",
31
- :is_filtered_by=>:filter_list},
32
- :name=>
33
- {:is_provided=>"nil",
34
- :is_not_provided=>"nil",
35
- :is=>"text",
36
- :is_not=>"text",
37
- :contains=>"text",
38
- :does_not_contain=>"text",
39
- :starts_with=>"text",
40
- :ends_with=>"text",
41
- :is_in=>"text_delimited",
42
- :is_not_in=>"text_delimited"},
43
- :admin=>
44
- {:is_provided=>"nil",
45
- :is_not_provided=>"nil",
46
- :is=>"boolean"
47
- },
48
- :birth_date =>
49
- {:is_provided=>"nil",
50
- :is_not_provided=>"nil",
51
- :is=>"date",
52
- :is_not=>"date",
53
- :is_after=>"date",
54
- :is_before=>"date",
55
- :is_in_the_range=>"date_range"
56
- },
57
- :created_at=>
58
- {:is_provided=>"nil",
59
- :is_not_provided=>"nil",
60
- :is=>"date_time",
61
- :is_not=>"date_time",
62
- :is_after=>"date_time",
63
- :is_before=>"date_time",
64
- :is_in_the_range=>"date_time_range",
65
- :is_on=>"single_date",
66
- :is_not_on=>"single_date"}
67
- }
68
- end
69
-
70
-
71
- end
data/uninstall.rb DELETED
@@ -1,24 +0,0 @@
1
- #--
2
- # Copyright (c) 2010 Michael Berkovich, Geni Inc
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- # Uninstall hook code here
data/will_filter.gemspec DELETED
@@ -1,7 +0,0 @@
1
- Gem::Specification.new do |spec|
2
- spec.name = "will_filter"
3
- spec.version = "0.0.1"
4
- spec.summary = "WillFilter"
5
- spec.authors = ["Me"]
6
- spec.files = Dir["{app,config,public,lib}/**/*"]
7
- end