forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparameter_filter.rb
More file actions
32 lines (29 loc) · 895 Bytes
/
parameter_filter.rb
File metadata and controls
32 lines (29 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- encoding: utf-8 -*-
module Github
# Allows you to specify parameters keys which will be preserved
# in parameters hash and its subhashes. Any keys from the nested
# hash that do not match will be removed.
module ParameterFilter
# Removes any keys from nested hashes that don't match predefiend keys
#
def filter!(keys, params, options={:recursive => true}) # :nodoc:
case params
when Hash, ParamsHash
params.keys.each do |k, v|
unless (keys.include?(k) or Github::Validations::VALID_API_KEYS.include?(k))
params.delete(k)
else
filter!(keys, params[k]) if options[:recursive]
end
end
when Array
params.map! do |el|
filter!(keys, el) if options[:recursive]
end
else
params
end
return params
end
end # Filter
end # Github