filtered_attributes 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -8
- data/lib/filtered_attributes.rb +3 -3
- data/lib/filtered_attributes/version.rb +1 -1
- data/test/dummy/log/test.log +46 -0
- metadata +5 -5
data/README.md
CHANGED
@@ -53,15 +53,15 @@ you</a>. However, this library will not work with Ruby versions prior to
|
|
53
53
|
|
54
54
|
filter\_attributes takes parameters:
|
55
55
|
|
56
|
-
- **resource_name**
|
57
|
-
|
58
|
-
|
59
|
-
- **options** (Hash), with keys
|
56
|
+
- **resource_name** prefix of method name, which returns filtered
|
57
|
+
attributes. ```:user``` will generate user_attributes method on
|
58
|
+
controller.
|
59
|
+
- **options** (Hash), with keys
|
60
60
|
- **:allow** (Array) list of allowed attributes, defaults to ```[]```
|
61
|
-
- **:as** (Symbol)
|
62
|
-
for example ```filter_attributes_for :user, as: :account```
|
63
|
-
will seek for attributes in ```params[:
|
64
|
-
|
61
|
+
- **:as** (Symbol) key in ```params``` hash, from where attributes are
|
62
|
+
taken, defaults to resource_name, for example ```filter_attributes_for :user, as: :account```
|
63
|
+
will seek for attributes in ```params[:account]```, but create helper method
|
64
|
+
user_attributes in your controller
|
65
65
|
- **:only** (Array) - list of actions that parameters will be filtered
|
66
66
|
for
|
67
67
|
- **:except** (Array) - opposite of **only**, can't be used together
|
data/lib/filtered_attributes.rb
CHANGED
@@ -12,7 +12,7 @@ module FilteredAttributes
|
|
12
12
|
instance_variable_get "@_#{options[:as]}_attributes"
|
13
13
|
end
|
14
14
|
|
15
|
-
self.send :private, "#{
|
15
|
+
self.send :private, "#{resource_name}_attributes".to_sym
|
16
16
|
|
17
17
|
filter_params = if options[:only]
|
18
18
|
{ only: options[:only] }
|
@@ -26,11 +26,11 @@ module FilteredAttributes
|
|
26
26
|
params_hash = if options[:attributes_hash].respond_to? :call
|
27
27
|
options[:attributes_hash].call params
|
28
28
|
else
|
29
|
-
params[
|
29
|
+
params[options[:as]]
|
30
30
|
end
|
31
31
|
|
32
32
|
if params_hash
|
33
|
-
instance_variable_set "@_#{
|
33
|
+
instance_variable_set "@_#{resource_name}_attributes", HashWithIndifferentAccess.new(
|
34
34
|
params_hash.select {|k,v| options[:allow].include?(k.to_s)}
|
35
35
|
)
|
36
36
|
end
|
data/test/dummy/log/test.log
CHANGED
@@ -465,3 +465,49 @@ Completed 200 OK in 3ms (Views: 2.3ms)
|
|
465
465
|
Processing by BasicFiltersController#create as HTML
|
466
466
|
Parameters: {"user"=>{"email"=>"foo@example.com", "admin"=>true}}
|
467
467
|
Completed 200 OK in 1ms (Views: 0.3ms)
|
468
|
+
Processing by AdvancedFiltersController#create as HTML
|
469
|
+
Parameters: {"account"=>{"email"=>"foo@example.com", "admin"=>true}}
|
470
|
+
Rendered text template (0.0ms)
|
471
|
+
Completed 200 OK in 12ms (Views: 11.9ms)
|
472
|
+
Processing by AdvancedFiltersController#update as HTML
|
473
|
+
Parameters: {"account"=>{"email"=>"foo@example.com", "admin"=>true}}
|
474
|
+
Rendered text template (0.0ms)
|
475
|
+
Completed 200 OK in 1ms (Views: 0.4ms)
|
476
|
+
Processing by AdvancedFiltersController#foo as HTML
|
477
|
+
Parameters: {"foo"=>{"bar"=>{"account"=>{"email"=>"foo@example.com", "admin"=>true}}}}
|
478
|
+
Completed 200 OK in 1ms (Views: 0.3ms)
|
479
|
+
Processing by AdvancedFiltersController#create as HTML
|
480
|
+
Parameters: {"account"=>{"email"=>"foo@example.com", "admin"=>true}}
|
481
|
+
Completed 200 OK in 0ms (Views: 0.2ms)
|
482
|
+
Processing by AdvancedFiltersController#update as HTML
|
483
|
+
Parameters: {"account"=>{"email"=>"foo@example.com", "admin"=>true}}
|
484
|
+
Completed 200 OK in 0ms (Views: 0.2ms)
|
485
|
+
Processing by BasicFiltersController#create as HTML
|
486
|
+
Parameters: {"user"=>{"email"=>"foo@example.com", "admin"=>true}}
|
487
|
+
Completed 200 OK in 3ms (Views: 2.2ms)
|
488
|
+
Processing by BasicFiltersController#create as HTML
|
489
|
+
Parameters: {"user"=>{"email"=>"foo@example.com", "admin"=>true}}
|
490
|
+
Completed 200 OK in 0ms (Views: 0.3ms)
|
491
|
+
Processing by AdvancedFiltersController#create as HTML
|
492
|
+
Parameters: {"account"=>{"email"=>"foo@example.com", "admin"=>true}}
|
493
|
+
Rendered text template (0.0ms)
|
494
|
+
Completed 200 OK in 12ms (Views: 11.9ms)
|
495
|
+
Processing by AdvancedFiltersController#update as HTML
|
496
|
+
Parameters: {"account"=>{"email"=>"foo@example.com", "admin"=>true}}
|
497
|
+
Rendered text template (0.0ms)
|
498
|
+
Completed 200 OK in 1ms (Views: 0.4ms)
|
499
|
+
Processing by AdvancedFiltersController#foo as HTML
|
500
|
+
Parameters: {"foo"=>{"bar"=>{"account"=>{"email"=>"foo@example.com", "admin"=>true}}}}
|
501
|
+
Completed 200 OK in 1ms (Views: 0.3ms)
|
502
|
+
Processing by AdvancedFiltersController#create as HTML
|
503
|
+
Parameters: {"account"=>{"email"=>"foo@example.com", "admin"=>true}}
|
504
|
+
Completed 200 OK in 0ms (Views: 0.2ms)
|
505
|
+
Processing by AdvancedFiltersController#update as HTML
|
506
|
+
Parameters: {"account"=>{"email"=>"foo@example.com", "admin"=>true}}
|
507
|
+
Completed 200 OK in 0ms (Views: 0.2ms)
|
508
|
+
Processing by BasicFiltersController#create as HTML
|
509
|
+
Parameters: {"user"=>{"email"=>"foo@example.com", "admin"=>true}}
|
510
|
+
Completed 200 OK in 2ms (Views: 2.1ms)
|
511
|
+
Processing by BasicFiltersController#create as HTML
|
512
|
+
Parameters: {"user"=>{"email"=>"foo@example.com", "admin"=>true}}
|
513
|
+
Completed 200 OK in 1ms (Views: 0.4ms)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filtered_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &16839620 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: 3.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *16839620
|
26
26
|
description: Different than attr_accessible/protected (that can still be used with
|
27
27
|
this gem), you can specify which parameters will be allowed in your controllers.
|
28
28
|
email:
|
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
segments:
|
87
87
|
- 0
|
88
|
-
hash:
|
88
|
+
hash: -3376348403804608473
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
none: false
|
91
91
|
requirements:
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
segments:
|
96
96
|
- 0
|
97
|
-
hash:
|
97
|
+
hash: -3376348403804608473
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
100
|
rubygems_version: 1.6.2
|