Sha256: a8b6b17e58f260cde7a6bf53fcc003cea2656bc90dcbd1915660ef8f6b09637e
Contents?: true
Size: 762 Bytes
Versions: 34
Compression:
Stored size: 762 Bytes
Contents
# frozen_string_literal: true class MiniDefender::Rules::DigitsBetween < MiniDefender::Rule def initialize(min, max) raise ArgumentError, 'Min must be a positive integer' unless min.is_a?(Integer) && min > 0 raise ArgumentError, 'Max must be a positive integer' unless max.is_a?(Integer) && max > 0 @min = min @max = max end def self.signature 'digits_between' end def self.make(args) self.new(args[0].to_i, args[1].to_i) end def passes?(attribute, value, validator) value = value&.to_s value.is_a?(String) && /\A[0-9]+\z/.match?(value) && value.length >= @min && value.length <= @max end def message(attribute, value, validator) "The field must contain digits between #{@min} and #{@max}." end end
Version data entries
34 entries across 34 versions & 1 rubygems