list_controls 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -13,11 +13,7 @@ Controller:
13
13
 
14
14
  class ProductsController < ApplicationController
15
15
 
16
- enable_list_controls
17
-
18
- def default_filters
19
- { 'state' => 'new' }
20
- end
16
+ enable_list_controls :default_filters => { 'state' => 'new' }
21
17
 
22
18
  def index
23
19
  @products = Product.all :conditions => { :state => @filters.state }
@@ -13,7 +13,13 @@ module ListControls
13
13
 
14
14
  attr_reader :filters
15
15
 
16
- before_filter :assign_filters
16
+ before_filter :list_controls_assign_filters
17
+
18
+ @list_controls_default_filters = options[:default_filters] || {}
19
+ end
20
+
21
+ def list_controls_default_filters
22
+ @list_controls_default_filters
17
23
  end
18
24
  end
19
25
 
@@ -21,15 +27,16 @@ module ListControls
21
27
 
22
28
  protected
23
29
 
24
- def default_filters
25
- {}
30
+ def list_controls_default_filters
31
+ f = self.class.list_controls_default_filters
32
+ f.is_a?(Proc) ? f.call(self) : f
26
33
  end
27
34
 
28
- def assign_filters
35
+ def list_controls_assign_filters
29
36
  session[:list_controls]||= {}
30
37
 
31
38
  session_store = session[:list_controls][self.class.to_s]||= {}
32
- session_store[:filters] ||= default_filters
39
+ session_store[:filters] ||= list_controls_default_filters
33
40
  session_store[:filters].merge!(params[:filters] || {})
34
41
 
35
42
  tmp_filters = session_store[:filters]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: list_controls
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Laurynas Butkus