Sha256: f8f7e9a430b5ae05e33549f1ff83b1fbd30f32b0537e42c069144031ebad6786
Contents?: true
Size: 747 Bytes
Versions: 6
Compression:
Stored size: 747 Bytes
Contents
module ValidatesFormattingOf class InvalidRegularExpression < StandardError def initialize(name) super("You must specify a Regexp, a proc, or a lambda for the #{name.inspect} validation.") end end class Validation attr_reader :name, :regex, :message def initialize(name, regexp, message = "is not correctly formatted") callable = regexp.respond_to? :call if !callable && regexp.class.to_s != "Regexp" raise InvalidRegularExpression.new(name) end @name, @regex, @message = name, regexp, message end def inspect "#<Validation name: #{name.inspect}, regex: #{regex.inspect}, message: #{message}>" end def to_s "<Validation::#{name.to_s}>" end end end
Version data entries
6 entries across 6 versions & 1 rubygems