params_cleaner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/params_cleaner.rb +31 -0
  2. metadata +63 -0
@@ -0,0 +1,31 @@
1
+ require "active_support/concern"
2
+ require "active_support/core_ext/hash/slice"
3
+
4
+ module ParamsCleaner
5
+ extend ActiveSupport::Concern
6
+
7
+ VERSION = "0.1.0"
8
+
9
+ def clean_params(root_params = params)
10
+ cleaned_params = root_params.map do |key, val|
11
+ if val.is_a?(Hash)
12
+ clean_values = clean_params(val.slice(*self.class._allowed_params[key]))
13
+ [key, clean_values]
14
+ else
15
+ [key, val]
16
+ end
17
+ end
18
+
19
+ Hash[cleaned_params]
20
+ end
21
+
22
+ module ClassMethods
23
+ def allowed_params(params_hash)
24
+ @allowed_params = params_hash
25
+ end
26
+
27
+ def _allowed_params
28
+ @allowed_params
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: params_cleaner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Drew Olson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70270187942100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70270187942100
25
+ description: Rails mass assignment protection in the controller
26
+ email:
27
+ - drew@drewolson.org
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/params_cleaner.rb
33
+ homepage: https://github.com/drewolson/params_cleaner
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ segments:
46
+ - 0
47
+ hash: -419507581123739491
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ segments:
55
+ - 0
56
+ hash: -419507581123739491
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.15
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Rails mass assignment protection in the controller
63
+ test_files: []