Sha256: 46f4a764c34ce3fca8fcbbb4c3f4f43d1a6ef12166e4cb5c2bd77585f33bd2cb
Contents?: true
Size: 1.06 KB
Versions: 80
Compression:
Stored size: 1.06 KB
Contents
# Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.io/terms.html require 'sqreen/rule_callback' 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
80 entries across 80 versions & 2 rubygems