strong_parameters_dsl 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 018dc2ab845cd370c8a1b4ebaec7975a00c8de1c
4
- data.tar.gz: 1e2264d99089254a34ddd43e6bb14bf7140d9f7f
3
+ metadata.gz: a17296277e45ca5e929c02120c88014394c0dea7
4
+ data.tar.gz: b7f853ceebe198fb1c2c6ae041e88dbff658e56f
5
5
  SHA512:
6
- metadata.gz: 27c35b3882c4ea0d538266949889701b810d879ed89eb8f5d70f83a0f944a719a919ab7d9105c3ca2059244db1ebafc502837bf75ab7554f8b6c6513ffe4f915
7
- data.tar.gz: 3319b8c977e50466945e58884be203352a9a8495f89d70baef671818ea7966efe66f289e8aebac57a813924de6bf4591da4d6a11d546f3031a95dc51e22f3767
6
+ metadata.gz: 9393f3baf8d3ed7f8c5615b5403d1c8911126177389dd7d005485f89f222be11ad093a79ecdeea042ce955652db2d473a832b47aa0315fff2df707556fc4b9b3
7
+ data.tar.gz: 718eb0c7f9efd9adc854d40a9e4b5bdf70f378e119f242267e82a2a026b4a47368aa2959019caaaf455bc762e4b2907de1e0b4861dda29cb066f004dbd31413d
data/README.md CHANGED
@@ -22,8 +22,17 @@ class UsersController < ActionController::Base
22
22
  strong_params :user do
23
23
  permit :name, :email, comments_attributes: [:comment, :post_id]
24
24
  end
25
+
25
26
  # ... or ...
26
27
  strong_params :user, permit: [:name, :email, comments_attributes: [:comment, :post_id]]
28
+
29
+ # an additional feature added is the ability to permit a key whose value is an arbitrary hash
30
+ strong_params :user, any: :data
31
+
32
+ # you can also mix and match any of the above approaches
33
+ strong_params :user, any: :data, permit: :name do
34
+ permit :more_keys, :and_stuff
35
+ end
27
36
 
28
37
 
29
38
  def create
@@ -31,7 +40,7 @@ class UsersController < ActionController::Base
31
40
  # to the strong_params call
32
41
  User.create user_params
33
42
 
34
- ... rest of code ...
43
+ # ... rest of code ...
35
44
  end
36
45
  end
37
46
  ```
@@ -14,6 +14,9 @@ module StrongParametersDsl
14
14
  # ... or ...
15
15
  # strong_params :user, permit: [name, :email, comments_attributes: [:comment, :post_id]]
16
16
  #
17
+ # # you can also declare a key whose value is a hash with arbitrary keys
18
+ # strong_params :activity, any: [:api_log], permit: [:event, :timestamp, :ip_address]
19
+ #
17
20
  #
18
21
  # def create
19
22
  # # the named param method is created based on the argument passed
@@ -28,15 +31,24 @@ module StrongParametersDsl
28
31
  param_method_name = "#{name}_params".to_sym
29
32
 
30
33
  define_method param_method_name do
31
- strongified = params.require name
34
+ params.require(name).tap do |strongified|
35
+ # use a block to assign permitted keys
36
+ strongified.instance_exec &block if block_given?
37
+
38
+ # mix and match using hash options to assign permitted values
39
+ if options[:permit].present?
40
+ strongified.permit *Array(options[:permit])
41
+ end
32
42
 
33
- if block_given?
34
- strongified.instance_exec &block
35
- else
36
- strongified.permit *Array(options[:permit])
43
+ # shortcut to adding a key whose value is a hash with arbitrary keys
44
+ if options[:any].present?
45
+ Array(options[:any]).map do |key|
46
+ strongified[key] = params[name][key]
47
+ end
48
+ end
37
49
  end
38
50
  end
39
-
51
+
40
52
  private param_method_name
41
53
  end
42
54
  end
@@ -1,3 +1,3 @@
1
1
  module StrongParametersDsl
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strong_parameters_dsl
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
  - Diego Salazar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-18 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler