class Sqreen::Rules::RegexpRuleCB

Generic regexp based matching

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/sqreen/rules/regexp_rule_cb.rb, line 12
def initialize(*args)
  super(*args)
  prepare
end

Public Instance Methods

match_regexp(str) click to toggle source
# File lib/sqreen/rules/regexp_rule_cb.rb, line 31
def match_regexp(str)
  @patterns.each do |pattern|
    return pattern if pattern.match?(str)
  end
  nil
end
prepare() click to toggle source
# File lib/sqreen/rules/regexp_rule_cb.rb, line 17
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