Sha256: a9cfae9f0859b6c8a0adfeae1b46cc8bb3c0574a2592f7be38696eb6f86412f9

Contents?: true

Size: 595 Bytes

Versions: 37

Compression:

Stored size: 595 Bytes

Contents

# frozen_string_literal: true

class MiniDefender::Rules::Regex < MiniDefender::Rule
  def initialize(pattern)
    raise ArgumentError, 'Expected a Regexp instance.' unless pattern.is_a?(Regexp)

    @pattern = pattern
  end

  def self.signature
    'regex'
  end

  def self.make(args)
    raise ArgumentError, 'Expected a pattern as input.' unless args.length > 0

    new(Regexp.compile(args.join(',')))
  end

  def passes?(attribute, value, validator)
    value.to_s.match?(@pattern)
  end

  def message(attribute, value, validator)
    "The value must match #{@pattern.to_s}."
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
mini_defender-0.6.8 lib/mini_defender/rules/regex.rb
mini_defender-0.6.7 lib/mini_defender/rules/regex.rb
mini_defender-0.6.5 lib/mini_defender/rules/regex.rb
mini_defender-0.6.4 lib/mini_defender/rules/regex.rb
mini_defender-0.6.3 lib/mini_defender/rules/regex.rb
mini_defender-0.6.2 lib/mini_defender/rules/regex.rb
mini_defender-0.6.1 lib/mini_defender/rules/regex.rb
mini_defender-0.6.0 lib/mini_defender/rules/regex.rb
mini_defender-0.5.8 lib/mini_defender/rules/regex.rb
mini_defender-0.5.7 lib/mini_defender/rules/regex.rb
mini_defender-0.5.6 lib/mini_defender/rules/regex.rb
mini_defender-0.5.5 lib/mini_defender/rules/regex.rb
mini_defender-0.5.4 lib/mini_defender/rules/regex.rb
mini_defender-0.5.3 lib/mini_defender/rules/regex.rb
mini_defender-0.5.2 lib/mini_defender/rules/regex.rb
mini_defender-0.5.1 lib/mini_defender/rules/regex.rb
mini_defender-0.5.0 lib/mini_defender/rules/regex.rb
mini_defender-0.4.1 lib/mini_defender/rules/regex.rb
mini_defender-0.4.0 lib/mini_defender/rules/regex.rb
mini_defender-0.3.14 lib/mini_defender/rules/regex.rb