class method
self.precompile_filters
Ruby on Rails 7.1.6
Since v7.1.6Signature
self.precompile_filters(filters)
Precompiles an array of filters that otherwise would be passed directly to #initialize. Depending on the quantity and types of filters, precompilation can improve filtering performance, especially in the case where the ParameterFilter instance itself cannot be retained (but the precompiled filters can be retained).
filters = [/foo/, :bar, "nested.baz", /nested\.qux/] precompiled = ActiveSupport::ParameterFilter.precompile_filters(filters) # => [/(?-mix:foo)|(?i:bar)/, /(?i:nested\.baz)|(?-mix:nested\.qux)/] ActiveSupport::ParameterFilter.new(precompiled)
Parameters
-
filtersreq
Source
# File activesupport/lib/active_support/parameter_filter.rb, line 55
def self.precompile_filters(filters)
filters, patterns = filters.partition { |filter| filter.is_a?(Proc) }
patterns.map! do |pattern|
pattern.is_a?(Regexp) ? pattern : "(?i:#{Regexp.escape pattern.to_s})"
end
deep_patterns = patterns.extract! { |pattern| pattern.to_s.include?("\\.") }
filters << Regexp.new(patterns.join("|")) if patterns.any?
filters << Regexp.new(deep_patterns.join("|")) if deep_patterns.any?
filters
end
Defined in activesupport/lib/active_support/parameter_filter.rb line 55
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::ParameterFilter