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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e90f42cf5877e784de5126dc00f1ee59f6d78ab4
4
- data.tar.gz: 50293c18b6b72b49329208bfbbe8e28d8e83855e
3
+ metadata.gz: 4bc10c6c7321ddd7522aba2a97ea89fbdef76418
4
+ data.tar.gz: bd8da917b51e818687433dac3e52f628806fd4cd
5
5
  SHA512:
6
- metadata.gz: 15b44d865dd742febb1b203ad9a453effc39cd4c51b75afb1ad60cadbadf6b7fb57c09ed12afa8375fd7e4a41d956f78700b28c4544639aab170c7f47ab2ac24
7
- data.tar.gz: 44674e64b057061e6b82622d69a453da0bd46cfb2a49ccf82f9b6a86dccc64f6baa88cff82e6a23bdaa08af2ebafe436de0dd24135f158a9d92e87801dd17906
6
+ metadata.gz: da3de8e23c850ab80e1287017823e48e1f4897a0a7da475f9ccd84019bb282f1f5054d40dd04ce5a0ad3edac5d55d64457ae7ba8f4d13f904b36e282db6cf988
7
+ data.tar.gz: 5d65041d63fdb6e62aedc9429e10f9a9c98a23832ef07d584851e05f62fc8f16011dba3bb014bef657f7d330ecf0fff5df332db80e75edc76689961e557623a4
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
  .rspec_status
13
13
 
14
14
  .byebug_history
15
+
16
+ *.gem
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class FilterParam
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  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.0
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-10 00:00:00.000000000 Z
11
+ date: 2017-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler