Sha256: f4308c7cbf5401f9c5d143e776d5f19f991168e314bba103182d8ccfaf1d9ffd
Contents?: true
Size: 1.08 KB
Versions: 39
Compression:
Stored size: 1.08 KB
Contents
# typed: ignore # Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.com/terms.html require 'sqreen/rules/rule_cb' module Sqreen module Rules # Generic regexp based matching class RegexpRuleCB < RuleCB def initialize(*args) super(*args) prepare end def prepare @patterns = [] raw_patterns = @data['values'] if raw_patterns.nil? msg = "no key 'values' in data (had #{@data.keys})" raise Sqreen::Exception, msg end @patterns = raw_patterns.map do |pattern| Regexp.compile(pattern, Regexp::IGNORECASE) end end if Regexp.new('').respond_to?(:match?) def match_regexp(str) @patterns.each do |pattern| return pattern if pattern.match?(str) end nil end else def match_regexp(str) @patterns.each do |pattern| return pattern if pattern.match(str) end nil end end end end end
Version data entries
39 entries across 39 versions & 1 rubygems