param_protected 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ group :development do
5
+ gem "jeweler"
6
+ end
7
+
8
+ group :test do
9
+ gem "rails", "~> 3.1.0"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,93 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.1.1)
5
+ actionpack (= 3.1.1)
6
+ mail (~> 2.3.0)
7
+ actionpack (3.1.1)
8
+ activemodel (= 3.1.1)
9
+ activesupport (= 3.1.1)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ i18n (~> 0.6)
13
+ rack (~> 1.3.2)
14
+ rack-cache (~> 1.1)
15
+ rack-mount (~> 0.8.2)
16
+ rack-test (~> 0.6.1)
17
+ sprockets (~> 2.0.2)
18
+ activemodel (3.1.1)
19
+ activesupport (= 3.1.1)
20
+ builder (~> 3.0.0)
21
+ i18n (~> 0.6)
22
+ activerecord (3.1.1)
23
+ activemodel (= 3.1.1)
24
+ activesupport (= 3.1.1)
25
+ arel (~> 2.2.1)
26
+ tzinfo (~> 0.3.29)
27
+ activeresource (3.1.1)
28
+ activemodel (= 3.1.1)
29
+ activesupport (= 3.1.1)
30
+ activesupport (3.1.1)
31
+ multi_json (~> 1.0)
32
+ arel (2.2.1)
33
+ builder (3.0.0)
34
+ erubis (2.7.0)
35
+ git (1.2.5)
36
+ hike (1.2.1)
37
+ i18n (0.6.0)
38
+ jeweler (1.6.4)
39
+ bundler (~> 1.0)
40
+ git (>= 1.2.5)
41
+ rake
42
+ json (1.6.1)
43
+ mail (2.3.0)
44
+ i18n (>= 0.4.0)
45
+ mime-types (~> 1.16)
46
+ treetop (~> 1.4.8)
47
+ mime-types (1.17.2)
48
+ multi_json (1.0.3)
49
+ polyglot (0.3.3)
50
+ rack (1.3.5)
51
+ rack-cache (1.1)
52
+ rack (>= 0.4)
53
+ rack-mount (0.8.3)
54
+ rack (>= 1.0.0)
55
+ rack-ssl (1.3.2)
56
+ rack
57
+ rack-test (0.6.1)
58
+ rack (>= 1.0)
59
+ rails (3.1.1)
60
+ actionmailer (= 3.1.1)
61
+ actionpack (= 3.1.1)
62
+ activerecord (= 3.1.1)
63
+ activeresource (= 3.1.1)
64
+ activesupport (= 3.1.1)
65
+ bundler (~> 1.0)
66
+ railties (= 3.1.1)
67
+ railties (3.1.1)
68
+ actionpack (= 3.1.1)
69
+ activesupport (= 3.1.1)
70
+ rack-ssl (~> 1.3.2)
71
+ rake (>= 0.8.7)
72
+ rdoc (~> 3.4)
73
+ thor (~> 0.14.6)
74
+ rake (0.9.2.2)
75
+ rdoc (3.11)
76
+ json (~> 1.4)
77
+ sprockets (2.0.3)
78
+ hike (~> 1.2)
79
+ rack (~> 1.0)
80
+ tilt (~> 1.1, != 1.3.0)
81
+ thor (0.14.6)
82
+ tilt (1.3.3)
83
+ treetop (1.4.10)
84
+ polyglot
85
+ polyglot (>= 0.3.1)
86
+ tzinfo (0.3.30)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ jeweler
93
+ rails (~> 3.1.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 3.0.0
@@ -2,4 +2,5 @@ require "param_protected/constants"
2
2
  require "param_protected/protector"
3
3
  require "param_protected/controller_modifications"
4
4
 
5
- ActionController::Base.extend(ParamProtected::ControllerModifications)
5
+ ActionController::Base.send(:include, ParamProtected::ControllerModifications)
6
+
@@ -1,57 +1,43 @@
1
1
  module ParamProtected
2
2
  module ControllerModifications
3
-
4
- def self.extended(action_controller)
5
- action_controller.class_eval do
6
- extend ClassMethods
7
- singleton_class.alias_method_chain :inherited, :protector
8
- include InstanceMethods
9
- alias_method_chain :params, :protection
10
- end
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ alias_method_chain :params, :protection
11
7
  end
12
-
8
+
13
9
  module ClassMethods
14
-
10
+ def _protector
11
+ @_protector ||= Protector.new
12
+ end
13
+
14
+ def _protector=(value)
15
+ @_protector = value
16
+ end
17
+
15
18
  def param_protected(params, actions = nil)
16
- Protector.instance(self).declare_protection(params, actions, BLACKLIST)
19
+ _protector.declare_protection(params, actions, BLACKLIST)
17
20
  end
18
-
21
+
19
22
  def param_accessible(params, actions = nil)
20
- Protector.instance(self).declare_protection(params, actions, WHITELIST)
23
+ _protector.declare_protection(params, actions, WHITELIST)
21
24
  end
22
25
 
23
- def inherited_with_protector(controller)
24
- inherited_without_protector(controller)
25
-
26
- if defined? @pp_protector
27
- controller.instance_variable_set :@pp_protector, @pp_protector.dup
28
- controller.class_eval { attr_reader :pp_protector }
29
- end
30
-
26
+ def inherited(m)
27
+ m._protector = _protector.dup
28
+ super
31
29
  end
32
-
33
30
  end
34
-
31
+
35
32
  module InstanceMethods
36
-
33
+ def _protector
34
+ self.class._protector
35
+ end
36
+
37
37
  def params_with_protection
38
-
39
- # #params is called internally by ActionController::Base a few times before an action is dispatched,
40
- # thus we can't filter and cache it right off the bat. We have to wait for #action_name to be present
41
- # to know that we're really in an action and @_params actually contains something. Then we can filter
42
- # and cache it.
43
-
44
- if action_name.blank?
45
- params_without_protection
46
- elsif @params_protected
47
- @params_protected
48
- else
49
- @params_protected = Protector.instance(self.class).protect(self, params_without_protection, action_name)
50
- end
51
-
38
+ return params_without_protection if action_name.blank?
39
+ @params_with_protection ||= _protector.protect(self, params_without_protection, action_name)
52
40
  end
53
-
54
41
  end
55
-
56
42
  end
57
43
  end
@@ -1,14 +1,5 @@
1
1
  module ParamProtected
2
2
  class Protector
3
-
4
- def self.instance(controller)
5
- unless controller.respond_to?(:pp_protector)
6
- controller.class_eval{ @pp_protector = Protector.new }
7
- controller.singleton_class.class_eval { attr_reader :pp_protector }
8
- end
9
- controller.pp_protector
10
- end
11
-
12
3
  def initialize
13
4
  @protections = []
14
5
  end
@@ -16,13 +7,13 @@ module ParamProtected
16
7
  def initialize_copy(copy)
17
8
  copy.instance_variable_set(:@protections, deep_copy(@protections))
18
9
  end
19
-
10
+
20
11
  def declare_protection(params, options, exclusivity)
21
12
  params = normalize_params(params)
22
13
  actions, condition = normalize_options(options)
23
14
  @protections << [params, actions, condition, exclusivity]
24
15
  end
25
-
16
+
26
17
  def protect(controller, controller_params, action_name)
27
18
  deep_copy(controller_params).tap do |params|
28
19
  protections_for_action(controller, action_name).each do |exclusivity, protected_params|
@@ -30,7 +21,7 @@ module ParamProtected
30
21
  end
31
22
  end
32
23
  end
33
-
24
+
34
25
  private
35
26
 
36
27
  def protections_for_action(controller, action_name)
@@ -42,15 +33,15 @@ module ParamProtected
42
33
  end
43
34
  end
44
35
 
45
- # Merge protections for the same params into one so as to allow extension of them
36
+ # Merge protections for the same params into one so as to allow extension of them
46
37
  # in inheriting controllers.
47
- #
38
+ #
48
39
  # Mutating the first argument is okay since this method is used within inject only.
49
- #
40
+ #
50
41
  # Example:
51
42
  # merge_protections({ :foo => { :qux => nil }, :bar => { :baz => nil, :qux => nil } },
52
43
  # { :foo => { :baz => nil, :qux => { :foo => nil } } })
53
- # =>
44
+ # =>
54
45
  #
55
46
  # { :foo => { :baz => nil, :qux => { :foo => nil } }, :bar => { :baz =>nil, :qux => nil } }
56
47
  def merge_protections(protections, protected_params)
@@ -64,10 +55,10 @@ module ParamProtected
64
55
 
65
56
  protections
66
57
  end
67
-
58
+
68
59
  # When specifying params to protect, we allow a combination of arrays and hashes much like how
69
60
  # ActiveRecord::Base#find's :include options works. This method normalizes that into just nested hashes,
70
- # stringifying the keys and setting all values to nil. This format is easier/faster to work with when
61
+ # stringifying the keys and setting all values to nil. This format is easier/faster to work with when
71
62
  # filtering the controller params.
72
63
  # Example...
73
64
  # [:a, {:b => [:c, :d]}]
@@ -95,7 +86,7 @@ module ParamProtected
95
86
  k.to_s
96
87
  end
97
88
  end
98
-
89
+
99
90
  # When specifying which actions param protection apply to, we allow a format like this...
100
91
  # :only => [:action1, :action2]
101
92
  # This method normalizes that to...
@@ -118,16 +109,16 @@ module ParamProtected
118
109
  actions = actions.collect{ |action| action.try(:to_s) }
119
110
 
120
111
  condition = condition.first || :if
121
-
112
+
122
113
  if options.has_key?(condition)
123
114
  condition_value = options[condition]
124
115
  else
125
116
  condition_value = true
126
117
  end
127
-
118
+
128
119
  [[scope, *actions], [condition, condition_value]]
129
120
  end
130
-
121
+
131
122
  # When #dup just isn't enough... :P
132
123
  def deep_copy(object)
133
124
  try_to_clone(object).tap do |new_object|
@@ -139,7 +130,7 @@ module ParamProtected
139
130
  end
140
131
  end
141
132
  end
142
-
133
+
143
134
  # Some objects are not dupable... like TrueClass, FalseClass and NilClass.
144
135
  def try_to_clone(object)
145
136
  object.clone
@@ -163,7 +154,7 @@ module ParamProtected
163
154
  result
164
155
  end
165
156
  end
166
-
157
+
167
158
  def action_matches?(scope, actions, action_name)
168
159
  if action_name.blank?
169
160
  false
@@ -175,7 +166,7 @@ module ParamProtected
175
166
  raise ArgumentError, "unexpected scope (#{scope}), expected :only or :except"
176
167
  end
177
168
  end
178
-
169
+
179
170
  def filter_params(protected_params, params, exclusivity)
180
171
  return unless params.kind_of?(Hash)
181
172
  return if protected_params.nil?
@@ -195,7 +186,7 @@ module ParamProtected
195
186
  key_matches?(k, key)
196
187
  end.try(:last)
197
188
  end
198
-
189
+
199
190
  def key_exists?(protected_params, key)
200
191
  protected_params.any? do |k,v|
201
192
  key_matches?(k, key)
@@ -1,98 +1,77 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{param_protected}
8
- s.version = "2.0.0"
8
+ s.version = "3.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Christopher J. Bottaro"]
12
- s.date = %q{2010-10-18}
11
+ s.authors = [%q{Christopher J. Bottaro}]
12
+ s.date = %q{2011-11-02}
13
13
  s.description = %q{Provides two class methods on ActiveController::Base that filter the params hash for that controller's actions. You can think of them as the controller analog of attr_protected and attr_accessible.}
14
14
  s.email = %q{cjbottaro@alumni.cs.utexas.edu}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  "CHANGELOG",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "init.rb",
26
- "lib/param_protected.rb",
27
- "lib/param_protected/constants.rb",
28
- "lib/param_protected/controller_modifications.rb",
29
- "lib/param_protected/protector.rb",
30
- "param_protected.gemspec",
31
- "test/accessible_except_test.rb",
32
- "test/accessible_only_test.rb",
33
- "test/app_root/.gitignore",
34
- "test/app_root/Gemfile",
35
- "test/app_root/app/controllers/accessible_except_controller.rb",
36
- "test/app_root/app/controllers/accessible_only_controller.rb",
37
- "test/app_root/app/controllers/application_controller.rb",
38
- "test/app_root/app/controllers/conditions_controller.rb",
39
- "test/app_root/app/controllers/inherited_users_controller.rb",
40
- "test/app_root/app/controllers/merge_controller.rb",
41
- "test/app_root/app/controllers/protected_controller.rb",
42
- "test/app_root/app/controllers/users_controller.rb",
43
- "test/app_root/config.ru",
44
- "test/app_root/config/application.rb",
45
- "test/app_root/config/boot.rb",
46
- "test/app_root/config/environment.rb",
47
- "test/app_root/config/routes.rb",
48
- "test/app_root/lib/console_with_fixtures.rb",
49
- "test/app_root/script/rails",
50
- "test/conditions_controller_test.rb",
51
- "test/inherited_users_controller_test.rb",
52
- "test/merge_controller_test.rb",
53
- "test/protected_controller_test.rb",
54
- "test/protector_test.rb",
55
- "test/test_helper.rb",
56
- "test/users_controller_test.rb"
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "init.rb",
28
+ "lib/param_protected.rb",
29
+ "lib/param_protected/constants.rb",
30
+ "lib/param_protected/controller_modifications.rb",
31
+ "lib/param_protected/protector.rb",
32
+ "param_protected.gemspec",
33
+ "test/accessible_except_test.rb",
34
+ "test/accessible_only_test.rb",
35
+ "test/app_root/.gitignore",
36
+ "test/app_root/Gemfile",
37
+ "test/app_root/app/controllers/accessible_except_controller.rb",
38
+ "test/app_root/app/controllers/accessible_only_controller.rb",
39
+ "test/app_root/app/controllers/application_controller.rb",
40
+ "test/app_root/app/controllers/conditions_controller.rb",
41
+ "test/app_root/app/controllers/inherited_users_controller.rb",
42
+ "test/app_root/app/controllers/merge_controller.rb",
43
+ "test/app_root/app/controllers/protected_controller.rb",
44
+ "test/app_root/app/controllers/users_controller.rb",
45
+ "test/app_root/config.ru",
46
+ "test/app_root/config/application.rb",
47
+ "test/app_root/config/boot.rb",
48
+ "test/app_root/config/environment.rb",
49
+ "test/app_root/config/routes.rb",
50
+ "test/app_root/lib/console_with_fixtures.rb",
51
+ "test/app_root/script/rails",
52
+ "test/conditions_controller_test.rb",
53
+ "test/inherited_users_controller_test.rb",
54
+ "test/merge_controller_test.rb",
55
+ "test/protected_controller_test.rb",
56
+ "test/protector_test.rb",
57
+ "test/test_helper.rb",
58
+ "test/users_controller_test.rb"
57
59
  ]
58
60
  s.homepage = %q{http://github.com/cjbottaro/param_protected}
59
- s.rdoc_options = ["--charset=UTF-8"]
60
- s.require_paths = ["lib"]
61
- s.rubygems_version = %q{1.3.7}
61
+ s.require_paths = [%q{lib}]
62
+ s.rubygems_version = %q{1.8.7}
62
63
  s.summary = %q{Filter unwanted parameters in your controllers and actions.}
63
- s.test_files = [
64
- "test/accessible_except_test.rb",
65
- "test/accessible_only_test.rb",
66
- "test/app_root/app/controllers/accessible_except_controller.rb",
67
- "test/app_root/app/controllers/accessible_only_controller.rb",
68
- "test/app_root/app/controllers/application_controller.rb",
69
- "test/app_root/app/controllers/conditions_controller.rb",
70
- "test/app_root/app/controllers/inherited_users_controller.rb",
71
- "test/app_root/app/controllers/merge_controller.rb",
72
- "test/app_root/app/controllers/protected_controller.rb",
73
- "test/app_root/app/controllers/users_controller.rb",
74
- "test/app_root/config/application.rb",
75
- "test/app_root/config/boot.rb",
76
- "test/app_root/config/environment.rb",
77
- "test/app_root/config/routes.rb",
78
- "test/app_root/lib/console_with_fixtures.rb",
79
- "test/conditions_controller_test.rb",
80
- "test/inherited_users_controller_test.rb",
81
- "test/merge_controller_test.rb",
82
- "test/protected_controller_test.rb",
83
- "test/protector_test.rb",
84
- "test/test_helper.rb",
85
- "test/users_controller_test.rb"
86
- ]
87
64
 
88
65
  if s.respond_to? :specification_version then
89
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
90
66
  s.specification_version = 3
91
67
 
92
68
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
69
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
93
70
  else
71
+ s.add_dependency(%q<jeweler>, [">= 0"])
94
72
  end
95
73
  else
74
+ s.add_dependency(%q<jeweler>, [">= 0"])
96
75
  end
97
76
  end
98
77
 
metadata CHANGED
@@ -1,34 +1,40 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: param_protected
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 0
8
- - 0
9
- version: 2.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Christopher J. Bottaro
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-10-18 00:00:00 -05:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description: Provides two class methods on ActiveController::Base that filter the params hash for that controller's actions. You can think of them as the controller analog of attr_protected and attr_accessible.
12
+ date: 2011-11-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jeweler
16
+ requirement: &70253414744340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70253414744340
25
+ description: Provides two class methods on ActiveController::Base that filter the
26
+ params hash for that controller's actions. You can think of them as the controller
27
+ analog of attr_protected and attr_accessible.
22
28
  email: cjbottaro@alumni.cs.utexas.edu
23
29
  executables: []
24
-
25
30
  extensions: []
26
-
27
- extra_rdoc_files:
31
+ extra_rdoc_files:
28
32
  - LICENSE
29
33
  - README.rdoc
30
- files:
34
+ files:
31
35
  - CHANGELOG
36
+ - Gemfile
37
+ - Gemfile.lock
32
38
  - LICENSE
33
39
  - README.rdoc
34
40
  - Rakefile
@@ -65,58 +71,31 @@ files:
65
71
  - test/protector_test.rb
66
72
  - test/test_helper.rb
67
73
  - test/users_controller_test.rb
68
- has_rdoc: true
69
74
  homepage: http://github.com/cjbottaro/param_protected
70
75
  licenses: []
71
-
72
76
  post_install_message:
73
- rdoc_options:
74
- - --charset=UTF-8
75
- require_paths:
77
+ rdoc_options: []
78
+ require_paths:
76
79
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
80
+ required_ruby_version: !ruby/object:Gem::Requirement
78
81
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- segments:
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
83
87
  - 0
84
- version: "0"
85
- required_rubygems_version: !ruby/object:Gem::Requirement
88
+ hash: -3789331872057499608
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
90
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- segments:
91
- - 0
92
- version: "0"
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
93
95
  requirements: []
94
-
95
96
  rubyforge_project:
96
- rubygems_version: 1.3.7
97
+ rubygems_version: 1.8.7
97
98
  signing_key:
98
99
  specification_version: 3
99
100
  summary: Filter unwanted parameters in your controllers and actions.
100
- test_files:
101
- - test/accessible_except_test.rb
102
- - test/accessible_only_test.rb
103
- - test/app_root/app/controllers/accessible_except_controller.rb
104
- - test/app_root/app/controllers/accessible_only_controller.rb
105
- - test/app_root/app/controllers/application_controller.rb
106
- - test/app_root/app/controllers/conditions_controller.rb
107
- - test/app_root/app/controllers/inherited_users_controller.rb
108
- - test/app_root/app/controllers/merge_controller.rb
109
- - test/app_root/app/controllers/protected_controller.rb
110
- - test/app_root/app/controllers/users_controller.rb
111
- - test/app_root/config/application.rb
112
- - test/app_root/config/boot.rb
113
- - test/app_root/config/environment.rb
114
- - test/app_root/config/routes.rb
115
- - test/app_root/lib/console_with_fixtures.rb
116
- - test/conditions_controller_test.rb
117
- - test/inherited_users_controller_test.rb
118
- - test/merge_controller_test.rb
119
- - test/protected_controller_test.rb
120
- - test/protector_test.rb
121
- - test/test_helper.rb
122
- - test/users_controller_test.rb
101
+ test_files: []