Sha256: ad706e4ea8c780f25745d313bcba436d355978bb3961dd72d0a5223f1c0e7c90
Contents?: true
Size: 457 Bytes
Versions: 4
Compression:
Stored size: 457 Bytes
Contents
# frozen_string_literal: true module SimpleValidate class ValidatesFormatOf < ValidatesBase attr_accessor :regex def initialize(attribute, options) @regex = options[:with] super(attribute, options[:message] || "is incorrect format", options[:if] || proc { true }) end def valid?(instance) raise ArgumentError if regex.nil? || !regex.is_a?(Regexp) !!(instance.send(attribute) =~ regex) end end end
Version data entries
4 entries across 4 versions & 1 rubygems