Sha256: 7e43f600fd101451a96df251ab65690eaa7fafa010b06b0ddba472214ac28289

Contents?: true

Size: 852 Bytes

Versions: 99

Compression:

Stored size: 852 Bytes

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

      def match_regexp(str)
        @patterns.each do |pattern|
          return pattern if pattern.match(str)
        end
        nil
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 2 rubygems

Version Path
sqreen-1.11.0-java lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-alt-1.11.0 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.11.0 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.5-java lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-alt-1.10.5 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.5 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.4-java lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-alt-1.10.4 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.4 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.3-java lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-alt-1.10.3 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.3 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.2-java lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-alt-1.10.2 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.2 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.1-java lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-alt-1.10.1 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.1 lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-1.10.0-java lib/sqreen/rules_callbacks/regexp_rule.rb
sqreen-alt-1.10.0 lib/sqreen/rules_callbacks/regexp_rule.rb