rack-filter-param 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +6 -0
- data/lib/rack/filter_param.rb +20 -0
- data/lib/rack/filter_param/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bc10c6c7321ddd7522aba2a97ea89fbdef76418
|
4
|
+
data.tar.gz: bd8da917b51e818687433dac3e52f628806fd4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da3de8e23c850ab80e1287017823e48e1f4897a0a7da475f9ccd84019bb282f1f5054d40dd04ce5a0ad3edac5d55d64457ae7ba8f4d13f904b36e282db6cf988
|
7
|
+
data.tar.gz: 5d65041d63fdb6e62aedc9429e10f9a9c98a23832ef07d584851e05f62fc8f16011dba3bb014bef657f7d330ecf0fff5df332db80e75edc76689961e557623a4
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -45,6 +45,12 @@ Strip a parameter named `client_id` from a fuzzy path:
|
|
45
45
|
use Rack::FilterParam, { param: :client_id, path: /\A\/oauth/ }
|
46
46
|
```
|
47
47
|
|
48
|
+
Strip a parameter named `client_id` based on arbitrary logic:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
use Rack::FilterParam, { param: :client_id, if: -> (value) { ... } }
|
52
|
+
```
|
53
|
+
|
48
54
|
To filter multiple parameters, an array of parameters or options hashes can also be passed.
|
49
55
|
|
50
56
|
## Contributing
|
data/lib/rack/filter_param.rb
CHANGED
@@ -23,6 +23,8 @@ module Rack
|
|
23
23
|
|
24
24
|
def process_param(param)
|
25
25
|
return unless path_matches?(param)
|
26
|
+
return unless param_exists?(param)
|
27
|
+
return unless affirmative_conditional?(param)
|
26
28
|
|
27
29
|
param = param[:param] if param.is_a?(Hash)
|
28
30
|
|
@@ -43,6 +45,24 @@ module Rack
|
|
43
45
|
false
|
44
46
|
end
|
45
47
|
|
48
|
+
def param_exists?(param)
|
49
|
+
param = param.is_a?(Hash) ? param[:param] : param
|
50
|
+
params.has_key?(param.to_s)
|
51
|
+
end
|
52
|
+
|
53
|
+
def params
|
54
|
+
action_dispatch_parsed? ? action_dispatch_params : request.params
|
55
|
+
end
|
56
|
+
|
57
|
+
def affirmative_conditional?(param)
|
58
|
+
return true unless param.is_a?(Hash)
|
59
|
+
|
60
|
+
callable, param = param[:if], param[:param]
|
61
|
+
return true if callable.nil?
|
62
|
+
|
63
|
+
callable.call(params[param.to_s])
|
64
|
+
end
|
65
|
+
|
46
66
|
def delete_from_action_dispatch(param)
|
47
67
|
action_dispatch_parsed? && !!action_dispatch_params.delete(param.to_s)
|
48
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-filter-param
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Watson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|