@@ -100,37 +100,35 @@ def initialize(regexps, deep_regexps, blocks, mask:)
100
100
@mask = mask
101
101
end
102
102
103
- def call ( params , parents = [ ] , original_params = params )
103
+ def call ( params , full_parent_key = nil , original_params = params )
104
104
filtered_params = params . class . new
105
105
106
106
params . each do |key , value |
107
- filtered_params [ key ] = value_for_key ( key , value , parents , original_params )
107
+ filtered_params [ key ] = value_for_key ( key , value , full_parent_key , original_params )
108
108
end
109
109
110
110
filtered_params
111
111
end
112
112
113
- def value_for_key ( key , value , parents = [ ] , original_params = nil )
114
- parents . push ( key ) if deep_regexps
113
+ def value_for_key ( key , value , full_parent_key = nil , original_params = nil )
114
+ if deep_regexps
115
+ full_key = full_parent_key ? "#{ full_parent_key } .#{ key } " : key . to_s
116
+ end
117
+
115
118
if regexps . any? { |r | r . match? ( key . to_s ) }
116
119
value = @mask
117
- elsif deep_regexps && ( joined = parents . join ( "." ) ) && deep_regexps . any? { |r | r . match? ( joined ) }
120
+ elsif deep_regexps &. any? { |r | r . match? ( full_key ) }
118
121
value = @mask
119
122
elsif value . is_a? ( Hash )
120
- value = call ( value , parents , original_params )
123
+ value = call ( value , full_key , original_params )
121
124
elsif value . is_a? ( Array )
122
- # If we don't pop the current parent it will be duplicated as we
123
- # process each array value.
124
- parents . pop if deep_regexps
125
- value = value . map { |v | value_for_key ( key , v , parents , original_params ) }
126
- # Restore the parent stack after processing the array.
127
- parents . push ( key ) if deep_regexps
125
+ value = value . map { |v | value_for_key ( key , v , full_parent_key , original_params ) }
128
126
elsif blocks . any?
129
127
key = key . dup if key . duplicable?
130
128
value = value . dup if value . duplicable?
131
129
blocks . each { |b | b . arity == 2 ? b . call ( key , value ) : b . call ( key , value , original_params ) }
132
130
end
133
- parents . pop if deep_regexps
131
+
134
132
value
135
133
end
136
134
end
0 commit comments