cancan_strong_parameters 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,19 +23,19 @@ module CancanStrongParameters
23
23
  # supply a resource name for #load_resource
24
24
  #
25
25
  def permit_params *keys
26
- filter_strong_params :permit, [:create, :update], keys
26
+ filter_strong_params :permit, [:all], keys
27
27
  end
28
28
 
29
29
  # Like permit_params, but only applies to create action
30
30
  #
31
31
  def permit_params_on_create *keys
32
- filter_strong_params :permit, :create, keys
32
+ filter_strong_params :permit, [:create], keys
33
33
  end
34
34
 
35
35
  # Like permit_params, but only applies to update action
36
36
  #
37
37
  def permit_params_on_update *keys
38
- filter_strong_params :permit, :update, keys
38
+ filter_strong_params :permit, [:update], keys
39
39
  end
40
40
 
41
41
  # Like permit_params, but marks the params required
@@ -47,26 +47,30 @@ module CancanStrongParameters
47
47
  # Like require_params, but only applies to create action
48
48
  #
49
49
  def require_params_on_create *keys
50
- filter_strong_params :require, :create, keys
50
+ filter_strong_params :require, [:create], keys
51
51
  end
52
52
 
53
53
  # Like require_params, but only applies to update action
54
54
  #
55
55
  def require_params_on_update *keys
56
- filter_strong_params :require, :update, keys
56
+ filter_strong_params :require, [:update], keys
57
57
  end
58
58
 
59
59
  # Does a permit! at every level of the params to let everything through
60
60
  #
61
61
  def permit_all_params options = {}
62
- prepend_before_filter options.reverse_merge(:only => [:create, :update]) do
62
+ prepend_before_filter do
63
63
  self.params.deep_permit!
64
64
  end
65
65
  end
66
66
 
67
67
  def filter_strong_params method, actions, keys # :nodoc:
68
+ # Get hash from end of array
68
69
  hash = keys.extract_options!
69
70
  keys.flatten!
71
+
72
+ # Filter_options is passed to our before filter, e.g. sets when they run
73
+ filter_options = actions == [:all] ? {} : { :only => actions }
70
74
 
71
75
  # Handle attributes if permitted attributes are given for nested models
72
76
  if (hash.present? && keys.present?) || (hash.select{|k,v| v.is_a?(Array)} == hash)
@@ -77,7 +81,7 @@ module CancanStrongParameters
77
81
  # More at https://github.com/rails/strong_parameters/pull/51
78
82
  hash = hash.attributized.stringified
79
83
 
80
- prepend_before_filter :only => actions do
84
+ prepend_before_filter(filter_options) do
81
85
  resource_name = self.class.resource_name
82
86
 
83
87
  # @todo We have to stringify everything for 1.8.7 due to a bug in `strong_parameters`.
@@ -92,11 +96,11 @@ module CancanStrongParameters
92
96
  self.params[resource_name] = params[resource_name].standardized.send method, *parameters
93
97
  end
94
98
  elsif hash.present?
95
- prepend_before_filter :only => actions do
99
+ prepend_before_filter(filter_options) do
96
100
  self.params.merge! params.send(method, hash)
97
101
  end
98
102
  else
99
- prepend_before_filter :only => actions do
103
+ prepend_before_filter(filter_options) do
100
104
  resource_name = self.class.resource_name
101
105
  if params.has_key?(resource_name)
102
106
  self.params[resource_name] = params[resource_name].send method, *keys.stringified
@@ -1,3 +1,3 @@
1
1
  module CancanStrongParameters
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancan_strong_parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2012-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cancan