Class: ActionDispatch::Http::ParameterFilter::CompiledFilter
- Defined in:
- actionpack/lib/action_dispatch/http/parameter_filter.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#regexps ⇒ Object
readonly
Returns the value of attribute regexps.
Class Method Summary collapse
Instance Method Summary collapse
- #call(original_params) ⇒ Object
-
#initialize(regexps, blocks) ⇒ CompiledFilter
constructor
A new instance of CompiledFilter.
Constructor Details
#initialize(regexps, blocks) ⇒ CompiledFilter
Returns a new instance of CompiledFilter.
43 44 45 46 |
# File 'actionpack/lib/action_dispatch/http/parameter_filter.rb', line 43 def initialize(regexps, blocks) @regexps = regexps @blocks = blocks end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks
41 42 43 |
# File 'actionpack/lib/action_dispatch/http/parameter_filter.rb', line 41 def blocks @blocks end |
#regexps ⇒ Object (readonly)
Returns the value of attribute regexps
41 42 43 |
# File 'actionpack/lib/action_dispatch/http/parameter_filter.rb', line 41 def regexps @regexps end |
Class Method Details
.compile(filters) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'actionpack/lib/action_dispatch/http/parameter_filter.rb', line 21 def self.compile(filters) return lambda { |params| params.dup } if filters.empty? strings, regexps, blocks = [], [], [] filters.each do |item| case item when Proc blocks << item when Regexp regexps << item else strings << item.to_s end end regexps << Regexp.new(strings.join('|'), true) unless strings.empty? new regexps, blocks end |
Instance Method Details
#call(original_params) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'actionpack/lib/action_dispatch/http/parameter_filter.rb', line 48 def call(original_params) filtered_params = {} original_params.each do |key, value| if regexps.any? { |r| key =~ r } value = FILTERED elsif value.is_a?(Hash) value = call(value) elsif value.is_a?(Array) value = value.map { |v| v.is_a?(Hash) ? call(v) : v } elsif blocks.any? key = key.dup value = value.dup if value.duplicable? blocks.each { |b| b.call(key, value) } end filtered_params[key] = value end filtered_params end |