nifty-utils 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efcc49cd3535dc3280a81e6ed4168b7cbb6be10c
4
- data.tar.gz: 6b5292096b6f7bfc3dcb9848f97552063c9dbc3a
3
+ metadata.gz: f05855de1c90babf9382e281e12d9549caf5257e
4
+ data.tar.gz: abcdd1052203af95eb6831882d5abe3a6bb75af8
5
5
  SHA512:
6
- metadata.gz: df74a3e9c8263a01f56ba8aa337dab56b1f7800cd1459b1054fa16c168ecc6ae3a3540393e2c9a1afc6d90281d977978a5235b9e10ea13d49471b32fd6a5a8c6
7
- data.tar.gz: fc2419684a1adf2667039d683bd53892c2fe84c39b170c8d3bfed43b6b505f5b001a869e805887dad19f900434569c1ec6eead438612c8ca89e8067e8a3d9bf8
6
+ metadata.gz: fcdb86d6c4177aa7d7fba77e90f3bd4ad1006ba9070e772d35c59b031bd24eb0ee12e1c09a3933277b1780d83fb4491a881b4590df4954ce6d26872aee520f4d
7
+ data.tar.gz: 94655dae4c2e9577090f5bca4fd8990e802bcb7ac2c6074e7e98eaa6a079dee2929f18795ba0f959e0bc5779725774c6f1d89fde1c76dd0d481462c10504b5cb
@@ -0,0 +1,70 @@
1
+ module Nifty
2
+ module Utils
3
+ module AutoAttributePermit
4
+
5
+ def self.setup
6
+ ActionView::Helpers::FormBuilder.send :include, FormBuilderExtensions
7
+ ActionController::Parameters.send :include, StrongParameterExtensions
8
+ end
9
+
10
+ def self.verifier
11
+ @verifier ||= ActiveSupport::MessageVerifier.new(Rails.application.secrets.secret_key_base)
12
+ end
13
+
14
+ module StrongParameterExtensions
15
+ def self.included(base)
16
+ base.class_eval do
17
+ alias_method_chain :permit, :auto_attribute_permit
18
+ end
19
+ end
20
+
21
+ def permit_with_auto_attribute_permit(*filters)
22
+ if filters.delete(:auto)
23
+ fields = AutoAttributePermit.verifier.verify(self['permitted_fields'])
24
+ permit_without_auto_attribute_permit(*(fields | filters))
25
+ else
26
+ permit_without_auto_attribute_permit(*filters)
27
+ end
28
+ end
29
+ end
30
+
31
+ module FormBuilderExtensions
32
+ def self.included(base)
33
+ base.class_eval do
34
+ alias_method_chain :label, :auto_attribute_permit
35
+ alias_method_chain :submit, :auto_attribute_permit
36
+ end
37
+ end
38
+
39
+ def auto_permitted_attributes
40
+ @auto_permitted_attributes ||= []
41
+ end
42
+
43
+ def label_with_auto_attribute_permit(method, text = nil, options = {}, &block)
44
+ auto_permitted_attributes << method unless (text.is_a?(Hash) ? text : options)[:auto_permit] == false
45
+ label_without_auto_attribute_permit(method, text, options, &block)
46
+ end
47
+
48
+ def submit_with_auto_attribute_permit(value = nil, options = {})
49
+ value, options = nil, value if value.is_a?(Hash)
50
+ include_permit_field = options.delete(:include_auto_permit_field)
51
+ submit_button = submit_without_auto_attribute_permit(value, options)
52
+ unless include_permit_field == false
53
+ submit_button.safe_concat(self.auto_permitted_attributes_field)
54
+ else
55
+ submit_button
56
+ end
57
+ end
58
+
59
+ def encoded_auto_permitted_attributes
60
+ AutoAttributePermit.verifier.generate(auto_permitted_attributes)
61
+ end
62
+
63
+ def auto_permitted_attributes_field
64
+ @template.hidden_field_tag("#{@object_name}[permitted_fields]", encoded_auto_permitted_attributes)
65
+ end
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -1,5 +1,5 @@
1
1
  module Nifty
2
2
  module Utils
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nifty-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-19 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A set of useful utilties for Rails applications.
14
14
  email:
@@ -21,6 +21,7 @@ files:
21
21
  - lib/nifty/utils/active_record/default_value.rb
22
22
  - lib/nifty/utils/active_record/inquirer.rb
23
23
  - lib/nifty/utils/active_record/random_string.rb
24
+ - lib/nifty/utils/auto_attribute_permit.rb
24
25
  - lib/nifty/utils/extensions/core.rb
25
26
  - lib/nifty/utils/extensions/object.rb
26
27
  - lib/nifty/utils/extensions/string.rb