better_strong_params 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGVjYWI4MWNmN2M5ZTM3NjRmNGFmYjVmMTZjMzhhN2U5OGQ5NWVjZg==
5
- data.tar.gz: !binary |-
6
- Y2U1ZTFhMTRmN2Y3Yzg1YzU5OTFmMzAxNzIxYzc0ZGZiMjJlODM3OQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MGRlNWYzZTU3ZjUwN2YxYmRjNDA0NWM2OTgwNGEzYjAxOWY5ZTZjY2NjZGIy
10
- Yjc2NGM0MWE3MjViNzJkNGRjMGNhN2FmNTlhZjUyODk1MDE1M2YyMzU4ZGIw
11
- ODk5ZDc0ZDhmNzgwZjFkNDQxNDA5NGE1MTA5NjJkZTczNGFkZDc=
12
- data.tar.gz: !binary |-
13
- YmMyNjEyN2IwOTBkODNjODkyNGJiN2M4YWFhN2E1YWZmMTg5MDRjOGM5Nzlh
14
- ZTA3YjkzZTViNmM2OWIyMDljOTUxM2RiMTgwNTg0YzhkNDdmODE3YzBjNWQx
15
- OWQ0NmY1OWFmNjhiNzM3YzJkMGQ2NWFmN2IxOTM4ZjE0OGM0YmY=
2
+ SHA1:
3
+ metadata.gz: b59e698c9700c6b59debe8f0e6df3cb86b7accb8
4
+ data.tar.gz: 76aa30622e52567aa1e075f140771206ed01e721
5
+ SHA512:
6
+ metadata.gz: e4a97bf01255499ac381c5714c38403b6c475c7b32625ecc7c3da44f1c31eef07238889e9b69bbf75703bae52ebc77844abe2342d23ef6633c719f692f02b824
7
+ data.tar.gz: 84c12902fc815691f06e8c671b4647eab618f32cc3dd11035401159c22761cd4df769c26790de0b0748c25f1e3d9e8b5f5e8fabdb48f4f35de19aa656a6a5875
data/README.md CHANGED
@@ -49,7 +49,7 @@ for every controller action you set using `filter_parameters`, a method named `#
49
49
  ```ruby
50
50
  class UsersController < ApplicationController
51
51
 
52
- filter_parameters create: {post: [:title, :body]}
52
+ filter_parameters create: {user: [:name, :age]}
53
53
 
54
54
  def create
55
55
  @user = User.new(create_params) # => create_params is available via BetterStrongParams and the filter_parameters DSL.
@@ -62,6 +62,37 @@ for every controller action you set using `filter_parameters`, a method named `#
62
62
  end
63
63
  ```
64
64
 
65
+ or if you want a single whitelist params set for all of the controller methods, BetterStrongParams will automatically generate one method named after your controller's singular resource
66
+
67
+ ```ruby
68
+ class UsersController < ApplicationController
69
+
70
+ filter_parameters all: {user: [:name, :age]}
71
+
72
+ def create
73
+
74
+ # If you specify the 'all' option, user_params will be available.
75
+ @user = User.new(user_params)
76
+ if @user.save
77
+ redirect_to treasure_url
78
+ else
79
+ redirect_to jail_url
80
+ end
81
+ end
82
+
83
+ def update
84
+ @user = User.find(params[:id])
85
+ if @user.update_attributes(user_params)
86
+ redirect_to treasure_url
87
+ else
88
+ redirect_to jail_url
89
+ end
90
+ end
91
+
92
+ end
93
+ ```
94
+
95
+
65
96
  ## Contributing
66
97
 
67
98
  1. Fork it ( http://github.com/<my-github-username>/better_strong_params/fork )
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["elad@eizesus.com"]
11
11
  spec.summary = "Adds a DSL to ActionController that allows to add strong params filtering without adding a specific, dirty controller method."
12
12
  spec.description = ""
13
- spec.homepage = "https://github.com/ShinobiDevs/better_strong_params"
13
+ spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -1,3 +1,3 @@
1
1
  module BetterStrongParams
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -10,11 +10,19 @@ module BetterStrongParams
10
10
 
11
11
  module ClassMethods
12
12
  def filter_parameters(options = {})
13
+ params_method_name = options[:as] || self.name.demodulize.gsub(/Controller$/,'').singularize.downcase
13
14
  action_names = options.keys
14
- action_names.each do |action_name|
15
- define_method("#{action_name.to_s}_params") do
16
- base = options[action_name].keys.first
17
- params.require(base).permit(*options[action_name][base])
15
+ if action_names.first.to_sym == :all
16
+ define_method("#{params_method_name}_params") do
17
+ base = options[:all].keys.first
18
+ params.require(base).permit(*options[:all][base])
19
+ end
20
+ else
21
+ action_names.each do |action_name|
22
+ define_method("#{action_name.to_s}_params") do
23
+ base = options[action_name].keys.first
24
+ params.require(base).permit(*options[action_name][base])
25
+ end
18
26
  end
19
27
  end
20
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_strong_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elad Meidar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,42 +28,42 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: ''
@@ -87,7 +87,7 @@ files:
87
87
  - spec/fixtures/models/user.rb
88
88
  - spec/lib/better_strong_params_spec.rb
89
89
  - spec/spec_helper.rb
90
- homepage: https://github.com/ShinobiDevs/better_strong_params
90
+ homepage: ''
91
91
  licenses:
92
92
  - MIT
93
93
  metadata: {}
@@ -97,17 +97,17 @@ require_paths:
97
97
  - lib
98
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ! '>='
100
+ - - '>='
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ! '>='
105
+ - - '>='
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.0.7
110
+ rubygems_version: 2.2.2
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Adds a DSL to ActionController that allows to add strong params filtering